任何人都可以帮忙...... 我需要在其他事件中访问动态添加的复选框,我将分享我的代码
void bindMaterials()
{
try
{
SqlConnection Con = new SqlConnection(conString);
SqlCommand FCimsbindoptCommand = Con.CreateCommand();
FCimsbindoptCommand.Connection = Con;
FCimsbindoptCommand.CommandText = "select * from nhcms_privilege";
SqlDataAdapter FCimsSrchAdapter = new SqlDataAdapter(FCimsbindoptCommand);
DataTable FCimsSrchDataSet = new DataTable();
FCimsSrchAdapter.Fill(FCimsSrchDataSet);
int rowcount = FCimsSrchDataSet.Rows.Count;
var a = new List<string>();
foreach (DataRow row in FCimsSrchDataSet.Rows)
{
a.Add(row["Privilege_Name"].ToString());
}
string[] strdata = a.ToArray();
foreach (var value in a)
{
CheckBox checkbox = new CheckBox();
checkbox.ID = "chk" + value;
checkbox.Text = value;
Panel1.Controls.Add(checkbox);
}
}
catch (Exception e)
{
}
}
我想将这些复选框控件访问到按钮事件