【发布时间】:2013-04-18 18:02:56
【问题描述】:
我有几个动态创建的复选框,并且将显示现有的选择,但是当用户进行更改时,我想将它们存储回来。这是动态生成和选择的代码
private void Role(string role)
{
SystemUserDal dal = new SystemUserDal();
var userId = Guid.Parse(Request.QueryString["ID"].ToString());
var roles = dal.GetRolesList(userId);
foreach (KeyValuePair<Guid, string> r in roles)
{
CheckBox chk = new CheckBox();
chk.ID = r.Value;
chk.Text = r.Value;
if (role.Contains(r.Value))
{
chk.Checked = true;
}
rolepanel.Controls.Add(chk);
}
}
我正在尝试以下方法
private void GetCheckBoxes()
{
foreach (Control ctrl in rolepanel.Controls)
{
CheckBox c = ctrl as CheckBox;
string id = c.ID;
string role = c.Text;
}
}
当我单步执行代码时,它会遇到计数为 3 的 foreach 循环,但 ctl 为空。有什么线索吗?
【问题讨论】:
-
rolepanel的类型是什么? -
加载动态复选框的 asp 面板
-
programmer93 将加载动态复选框的 asp 面板
标签: c# asp.net .net c#-4.0 event-handling