asp.net取得复选框值代码
我们介绍关于利用asp教程.net 获取checkbox值的几种方法,
html代码
<form id="form1" runat="server">
<div>
<asp:label id="label1" runat="server" text="label" enableviewstate="false"></asp:label>
<asp:checkboxlist id="checkboxlist1" runat="server">
<asp:listitem>zhangsan</asp:listitem>
<asp:listitem>lisi</asp:listitem>
<asp:listitem>wangwu</asp:listitem>
<asp:listitem>zhaoliu</asp:listitem>
</asp:checkboxlist><asp:button id="button1" runat="server" text="button" onclick="button1_click" />
</div>
</form>
c获取值。
{
int i ;
string str = "";
for (i = 0; i <checkboxlist1.items.count; i++)
if (checkboxlist1.items[i].selected ) str+ =checkboxlist1.items[i].value;
label1.text=str;
}
下面讲一下关于
第一种:获得checkbox的值
string save_cbljl = "";
for (int i = 0; i < this.cbljl.items.count; i++)
{
if (this.cbljl.items[i].selected == true)
{
save_cbljl += this.cbljl.items[i].value + ",";
}
}
response.write(save_cbljl);string save_cbljl = "";
for (int i = 0; i < this.cbljl.items.count; i++)
{
if (this.cbljl.items[i].selected == true)
{
save_cbljl += this.cbljl.items[i].value + ",";
}
}
response.write(save_cbljl);
第二种:获得checkbox的值
string str_save_cbljl = "";
foreach (listitem li in cbljl.items)
{
if (li.selected == true)
{
str_save_cbljl += li.value + ",";
}
}
response.write(str_save_cbljl);
补充:asp.net教程,基础入门