メソッドを呼び出す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;
}
}
}
}
これを回避する方法はありますか?