我有一个调用方法的ListView
with 。EditItemTemplate
onItemEditing
在我的范围内,我ListView
有一个CheckBoxList
使用LINQ
.
在我的onItemEditing
方法中,我试图确定CheckBoxes
它们是否存在于将用户与部门链接的查找表中。
但是,当我加载时,即使我已在方法中将它们设置为选中,也不会检查EditItemTemplate
任何一个。CheckBoxes
onItemEditing
这是方法:
protected void onItemEditing(object sender, ListViewEditEventArgs e)
{
ListView1.EditIndex = e.NewEditIndex;
ListView1.DataBind();
int regId = Convert.ToInt32(((Label)ListView1.Items[e.NewEditIndex].FindControl("LblRegId")).Text);
CheckBoxList cbl = (CheckBoxList) ListView1.Items[e.NewEditIndex].FindControl("chkLstSectors");
//test to see if forcing first check box to be selected works - doesn't work
cbl.Items[0].Selected = true;
SqlConnection objConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DaresburyConnectionString"].ToString());
SqlCommand objCmd = new SqlCommand("select * from register_sectors where register_id= " + regId, objConn);
objConn.Open();
SqlDataReader objReader = objCmd.ExecuteReader();
if (objReader != null)
{
while (objReader.Read())
{
ListItem currentCheckBox = cbl.Items.FindByValue(objReader["sector_id"].ToString());
if (currentCheckBox != null)
{
currentCheckBox.Selected = true;
}
}
}
}
任何想法如何解决这个问题?