dhivya krishnamoorthy dhivya krishnamoorthy - 1 year ago 76
C# Question

Checkbox list need to be checked based on the values saved in DB

chkTypeofIncident.DataSource = from t2 in
where t2.IncidentTypeFlag== '2' select t2;

chkTypeofIncident.DataTextField = "Incidents";
chkTypeofIncident.DataValueField = "IncidentsMasterID";

I got the selected values using LINQ. but output was it always checked the last value in database.

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

Answer Source
foreach (var chk in CheckedInc)
chkTypeofIncident.Items.FindByValue(chk.IncidentsMasterID).Selected = true;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download