for (int i = 1; i < 8; i++)
{
CheckBox[i].Checked = true;
CheckBox[i].Text = "已開通";
}
瞎寫的代碼,想實現類似的功能,有八個 CheckBox ID也為CheckBox1~CheckBox8,想做個循環進行賦值
{
CheckBox[i].Checked = true;
CheckBox[i].Text = "已開通";
}
瞎寫的代碼,想實現類似的功能,有八個 CheckBox ID也為CheckBox1~CheckBox8,想做個循環進行賦值
{
CheckBox_i.Checked = true;
CheckBox_i.value= "已開通";
}
不过不知道你要赋的值是什么把
CheckBox命名为CheckBox_1 CheckBox_2 .....CheckBox_8
for(var =0;i<a.length;i++)
{
if(a[i].type==checkbox)
{
if(a[i].checked)
{
a[i].value="sssss";
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
CheckBox ck = null;
for (int i = 1; i <4; i++)
{
ck=form1.FindControl("CheckBox"+i.ToString()) as CheckBox;
ck.Checked = true;
ck.Text = "已开通";
}
}
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CheckBox ID="CheckBox3" runat="server" />
<asp:CheckBox ID="CheckBox2" runat="server" />
</div>
</form>
foreach (System.Windows.Forms.Control control in this.Controls)
{
if (control is checkbox)
{
checkbox cbx = new checkbox();
cbx = (checkbox )control;
cbx .Checked = true;
cbx .Text = "已開通";
}
}
{
ArrryList al = new ArrayList();
al(CheckBox1);
al(CheckBox2);
al(CheckBox3);
...
al(CheckBox8);
for (int i = 1; i < al.count; i++)
{
CheckBox chkBox = (CheckBox)al[i];
chkBox.Checked = true;
}}
Another way:private void setCheckBox()
{
ArrryList al = new ArrayList();
al.add(CheckBox1);
al.add(CheckBox2);
al.add(CheckBox3);
...
al.add(CheckBox8);
for (int i = 1; i < al.count; i++)
{
CheckBox chkBox = (CheckBox)al[i];
chkBox.Checked = true;
}}