我的任务是从数据库中读取条目并添加与每个条目对应的复选框
我已打开数据库连接并创建了复选框,但无法检查复选框的设置。我正在使用静态数组ck []
int count = 0;
while(dr.Read()) //Reading the Database
{
CheckBox temp = new CheckBox(); //Creating a temprory checkbox
temp.Text = dr[1].ToString();
temp.Checked = false; //Making the checkbox intitally empty
temp.ID = dr[0].ToString();
ck[count] = temp; //inserting the checkbox's references into the array
ck[count].CheckedChanged += new EventHandler(temp_CheckedChanged); //Adding the even handler
Panel1.Controls.Add(ck[count]); //Adding the checkbox to panel
LiteralControl lc = new LiteralControl("<br>");
Panel1.Controls.Add(lc);
count++;
}
void temp_CheckedChanged(object sender, EventArgs e) //handling the checking and unchecking of the checkbox
{
CheckBox ckb = (CheckBox)sender;
ck[index].Checked = !ck[index].Checked;
}
问题出现在复选框的 .Checked 条目中没有更新。
我在这里阅读了很多帖子并试图实现它们,但到目前为止还没有任何结果。我甚至尝试从我正在显示它的窗格中读取数据。