我得到了與複選框的變化量的CheckBoxList,和我做類似的東西:選擇複選框未承認爲
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int j = 0; j < CheckBoxList1.Items.Count; j++)
{
//LabelTest.Text = "Something"; It works here
if (CheckBoxList1.Items[j].Selected)
{
//LabelTest.Text = "Something 2"; It doesn't work here
TextBoxTest.Text = CheckBoxList1.Items[j].Text;
LabelTest.Text = CheckBoxList1.Items[j].Value;
}
}
}
當我檢查中,將「東西」是顯示在我的頁面上,但其餘的不是。 我試着寫我的「如果」也喜歡它:
if (!CheckBoxList1.Items[j].Selected)
而且做這樣的話,當我檢查一個盒子,我TextBoxTest顯示「106」,這是複選框我的總數,但不選中的框的數量。
我的CheckBoxList1有一個真正的autopostback。
感謝您的幫助,對不起我的英語不好。
可以u顯示其中u填充的CheckBoxList – Talha
當然,我問另外一個問題前面,一切(我認爲)的代碼就可以了:) http://stackoverflow.com/questions/10846445/selecting-one -checkbox-in-loop-generated-checkboxes-from-checkboxlist –
你什麼時候填充你的複選框?如果您在每個「Page_Load」上重新創建它們,則可能會覆蓋事實,即您已經選中了一個。 – geekchic