脚本宝典收集整理的这篇文章主要介绍了WebForm获取checkbox选中的值(几个简单的示例),脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
PS:最近在做权限管理这个模块,发现用checkbox的地方挺多的,于是写了个简单的例子,以供以后学习和使用。
1.前端页面:
<form id="form1" method="get" runat="server"> <input name="chk_PEr" type="checkbox" value="3" />张三 <input name="chk_per" type="checkbox" value="4" />李四 <input name="chk_per" type="checkbox" value="5" />王五 <input name="chk_per" type="checkbox" value="6" />赵六 <input name="chk_per" type="checkbox" value="7" />孙琦 <input name="chk_per" type="checkbox" value="8" />猪八 <input type="submIT" id="BTnOK" value="提交" /> </form>
2.后台方法:
#region 获取从前端页面回传过来的 CheckBox 的值 void GetCheckBoxValue() /// <summary> /// 获取从前端页面回传过来的 CheckBox 的值 /// <para>Request.Form["chk_per"] 以逗号分割,获取所有选中的 CheckBox 的值</para> /// </summary> PRivate void GetCheckBoxValue() { string user = Request["chk_per"]; string[] users = user.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); string s = string.Empty; foreach (VAR item in users) { s += item + " | "; } } #endregion
protected void Page_Load(object sender, Eventargs e) { if (IsPostBack) { //测试调用 GetCheckBoxValue(); } }
以上是脚本宝典为你收集整理的WebForm获取checkbox选中的值(几个简单的示例)全部内容,希望文章能够帮你解决WebForm获取checkbox选中的值(几个简单的示例)所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。