我在button1点击事件中动态创建了一个复选框数组。现在我想在另一个button2点击事件中检查其已检查的属性。由于复选框控件是在运行时动态创建的,因此我无法在button2单击事件中访问它。请有人帮我解决这个问题。
public void Display(ref string[] strDmn, ref string[][] strAvblty)
{
ch = new CheckBox[cntExt / 2];
strDomInfo = new string[cntExt / 2];
Table t = new Table();
t.Caption = "Domain Availablity";
t.BorderWidth = 1;
TableRow tr;
TableCell tc;
System.Drawing.ColorConverter colConvert = new ColorConverter();
for (int i = 0; i < (strDmn.Length); i++)
{
for (int l = 0; l < ((strAvblty[i].Length) / 2); l++)
{
tr = new TableRow();
tr.BackColor = (System.Drawing.Color)colConvert.ConvertFromString("#F0E8FF");
for (int j = 0; j < 4; j++)
{
//string k = strAvblty[i][(i * 2 + 1)];
tc = new TableCell();
tc.Width = 300;
switch (j)
{
case 0:
ch[k - 1] = new CheckBox();
strDomInfo[k - 1] = strDmn[i] + "." + strAvblty[i][(l * 2)];
if (strAvblty[i][(l * 2) + 1] == "available")
{ }
else { ch[k - 1].Enabled = false; }
tc.Controls.Add(ch[k - 1]);
break;
case 1: tc.Text = strDmn[i];
break;
case 2: tc.Text = strAvblty[i][(l * 2)];
break;
case 3: tc.Text = strAvblty[i][(l * 2) + 1];
break;
}
tr.Cells.Add(tc);
}
t.Rows.Add(tr);
}
}
// desiredPanel is your panel
Panel1.Controls.Add(t);
}
protected void btnAdd2Cart_Click(object sender, EventArgs e)
{
//******I have get the boolen check property here ******
}
答案 0 :(得分:0)
您必须在Page_Init
中创建这些复选框,并且应在回发时重新创建这些复选框。然后,您将能够获得Button2's click handler
protected void Page_Init(object sender, EventArgs e)
{
// Create here
}