动态创建checkbox的问题?????????

来源:百度知道 编辑:UC知道 时间:2024/05/14 13:21:20
我有一串0,1字符,标定某些多选框是否被选中,当我改变dropdownlist的值后就根据其值动态绑定一组多项框,并根据前面的0,1串确定是否被选中,我的代码如下:
protected void ddlModule_SelectedIndexChanged(object sender, EventArgs e)
{
//this.pHolderFunc.Visible = true;
int ID = Convert.ToInt32((sender as DropDownList).SelectedValue);
string sql = "select * from [AllFunc] where ModuleNum='" + ID + "'";
SqlDataReader sdr = Operate.sdr(sql);
while (sdr.Read())
{
count++;
this.pHolderFunc.Controls.Add(new LiteralControl("  "));
CheckBox cb = new CheckBox(); //动态生成checkbox
cb.ID = "cb"+count.ToString(); //本来想根据这个ID找的
cb.Text = sdr["FuncName"].ToString();
int FuncID = Convert.ToInt32(sdr["FuncNum"]);
cb.TabIndex = (short)FuncID;
if (userDate.Authori

你创建是没错,问题是你保存时去遍例Checkbox的时候错了
用Foreach遍例



foreach (System.Windows.Forms.Control control in this.Controls)//遍历Form上的所有控件
{
if (control is System.Windows.Forms.CheckBox)
{
System.Windows.Forms.CheckBox cb= (System.Windows.Forms.CheckBox)control;
cb.test = "111111";
}
}

只是给点提示。。。具体的希望你自己想