前台代码<form id="form1" runat="server">
<div id="DIV1" runat="server">
<input id="Checkbox1" runat="server" type="checkbox" />
<input id="Checkbox2" runat="server" type="checkbox" />
<input id="Checkbox3" runat="server" type="checkbox" />
<input id="Checkbox4" runat="server" type="checkbox" />
<input id="Checkbox5" runat="server" type="checkbox" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></div>
</form>
后台代码
protected void Page_Load(object sender, EventArgs e)
{ this.Checkbox1.Attributes["name"] = "my";
this.Checkbox2.Attributes["name"] = "my";
this.Checkbox3.Attributes["name"] = "my";
this.Checkbox4.Attributes["name"] = "my";
this.Checkbox5.Attributes["name"] = "my";
this.Checkbox1.Attributes["value"] = "val1";
this.Checkbox2.Attributes["value"] = "val2";
this.Checkbox3.Attributes["value"] = "val3";
this.Checkbox4.Attributes["value"] = "val4";
this.Checkbox5.Attributes["value"] = "val5";
} protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(Request.Form["my"]);
}
<div id="DIV1" runat="server">
<input id="Checkbox1" runat="server" type="checkbox" />
<input id="Checkbox2" runat="server" type="checkbox" />
<input id="Checkbox3" runat="server" type="checkbox" />
<input id="Checkbox4" runat="server" type="checkbox" />
<input id="Checkbox5" runat="server" type="checkbox" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></div>
</form>
后台代码
protected void Page_Load(object sender, EventArgs e)
{ this.Checkbox1.Attributes["name"] = "my";
this.Checkbox2.Attributes["name"] = "my";
this.Checkbox3.Attributes["name"] = "my";
this.Checkbox4.Attributes["name"] = "my";
this.Checkbox5.Attributes["name"] = "my";
this.Checkbox1.Attributes["value"] = "val1";
this.Checkbox2.Attributes["value"] = "val2";
this.Checkbox3.Attributes["value"] = "val3";
this.Checkbox4.Attributes["value"] = "val4";
this.Checkbox5.Attributes["value"] = "val5";
} protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(Request.Form["my"]);
}
Response.Write(Checkbox1.value);用foreach可循环取