WebForm获取checkbox选中的值(几个简单的示例)
PS:最近在做权限管理这个模块,发现用checkbox的地方挺多的,于是写了个简单的例子,以供以后学习和使用。
1.前端页面:
<formid="form1"method="get"runat="server"> <inputname="chk_per"type="checkbox"value="3"/>张三 <inputname="chk_per"type="checkbox"value="4"/>李四 <inputname="chk_per"type="checkbox"value="5"/>王五 <inputname="chk_per"type="checkbox"value="6"/>赵六 <inputname="chk_per"type="checkbox"value="7"/>孙琦 <inputname="chk_per"type="checkbox"value="8"/>猪八 <inputtype="submit"id="btnOK"value="提交"/> </form>
2.后台方法:
#region获取从前端页面回传过来的CheckBox的值voidGetCheckBoxValue()
///<summary>
///获取从前端页面回传过来的CheckBox的值
///<para>Request.Form["chk_per"]以逗号分割,获取所有选中的CheckBox的值</para>
///</summary>
privatevoidGetCheckBoxValue()
{
stringuser=Request["chk_per"];
string[]users=user.Split(new[]{","},StringSplitOptions.RemoveEmptyEntries);
strings=string.Empty;
foreach(variteminusers)
{
s+=item+"|";
}
}
#endregion
protectedvoidPage_Load(objectsender,EventArgse)
{
if(IsPostBack)
{
//测试调用
GetCheckBoxValue();
}
}热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志