网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 WebForm获取checkbox选中的值(几个简单的示例)
内容
    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 + " | ";
    }
    }
    #endregionprotected void Page_Load(object sender, EventArgs e)
    {
    if (IsPostBack)
    {
    //测试调用
    GetCheckBoxValue();
    }
    }
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/19 11:39:09