WebForm获取checkbox选中的值(几个简单的示例)

2025-05-29 0 64

PS:最近在做权限管理这个模块,发现用checkbox的地方挺多的,于是写了个简单的例子,以供以后学习和使用。

1.前端页面:

  1. <formid="form1"method="get"runat="server">
  2. <inputname="chk_per"type="checkbox"value="3"/>张三
  3. <inputname="chk_per"type="checkbox"value="4"/>李四
  4. <inputname="chk_per"type="checkbox"value="5"/>王五
  5. <inputname="chk_per"type="checkbox"value="6"/>赵六
  6. <inputname="chk_per"type="checkbox"value="7"/>孙琦
  7. <inputname="chk_per"type="checkbox"value="8"/>猪八
  8. <inputtype="submit"id="btnOK"value="提交"/>
  9. </form>

2.后台方法:

  1. #region获取从前端页面回传过来的CheckBox的值voidGetCheckBoxValue()
  2. ///<summary>
  3. ///获取从前端页面回传过来的CheckBox的值
  4. ///<para>Request.Form["chk_per"]以逗号分割,获取所有选中的CheckBox的值</para>
  5. ///</summary>
  6. privatevoidGetCheckBoxValue()
  7. {
  8. stringuser=Request["chk_per"];
  9. string[]users=user.Split(new[]{","},StringSplitOptions.RemoveEmptyEntries);
  10. strings=string.Empty;
  11. foreach(variteminusers)
  12. {
  13. s+=item+"|";
  14. }
  15. }
  16. #endregion
  1. protectedvoidPage_Load(objectsender,EventArgse)
  2. {
  3. if(IsPostBack)
  4. {
  5. //测试调用
  6. GetCheckBoxValue();
  7. }
  8. }
收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 WebForm获取checkbox选中的值(几个简单的示例) https://www.kuaiidc.com/102748.html

相关文章

发表评论
暂无评论