复选框列表需要根据保存在DB中的值进行检查
本文关键字:DB 进行检查 存在 保存 列表 复选框 | 更新日期: 2023-09-27 18:01:03
chkTypeofIncident.DataSource = from t2 in
dbl.usp_GetIncidentsType().AsQueryable()
where t2.IncidentTypeFlag== '2' select t2;
chkTypeofIncident.DataTextField = "Incidents";
chkTypeofIncident.DataValueField = "IncidentsMasterID";
chkTypeofIncident.DataBind();
我使用LINQ获得了选定的值。但输出总是检查数据库中的最后一个值。
var CheckedInc = from t2 in dbl.usp_GetIncidentsTypeDetail(Convert.ToInt32(HiddenIncidentRegisterID.Value)).AsQueryable()
select t2;
foreach(var chk in CheckedInc)
{
chkTypeofIncident.SelectedValue = chk.IncidentsMasterID.ToString();
}
foreach (var chk in CheckedInc)
{
chkTypeofIncident.Items.FindByValue(chk.IncidentsMasterID).Selected = true;
}
chkTypeofIncident.SelectedValue = CheckedInc.FirstOrDefault().IncidentsMasterID.ToString();
//here you also can use where condition