If your database stores a flag to determine the selected
CheckBox
items, then you could simply do something like:
for (int i = 0; i < CheckBoxList1.Items.Count; i++){
CheckBoxList1.Items[i].Selected = Convert.ToBoolean(dt.Rows[i]["IsSelected"]);
}
IsSelected
as boolean flag from your database.
Here's a quick example:
protected void FormView1_DataBound(object sender, EventArgs e)
{
if (FormView1.CurrentMode == FormViewMode.ReadOnly)
{
if (FormView1.Row.RowType == DataControlRowType.DataRow)
{
CheckBoxList cal = (CheckBoxList)FormView1.Row.Cells[0].FindControl("YourCheckBoxControlIDHere");
if (cbl= !null)
{
DataTable dt = ???;
for (int i = 0; i < cbl.Items.Count; i++){
cbl.Items[i].Selected = Convert.ToBoolean(dt.Rows[i]["IsSelected"]);
}
}
}
}
}