需要根据DB中保存的值检查复选框列表

时间:2016-08-05 10:35:05

标签: c#

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();
}

2 个答案:

答案 0 :(得分:1)

immediately available

答案 1 :(得分:0)

 chkTypeofIncident.SelectedValue = CheckedInc.FirstOrDefault().IncidentsMasterID.ToString(); 
 //here you also can use where condition