私はのEditItemTemplate
で、方法はonItemEditing
です。CheckBoxListを含むListView - チェックされていない選択項目
私のListView
には、LINQ
を使用してCheckBoxList
がバインドされています。
私の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;
}
}
}
}
任意のアイデアはどのようにこの問題を回避するには:
ここでの方法は?
コントロールをどこに作成しましたか?ロード時に、initで? –