zoukankan      html  css  js  c++  java
  • CheckBoxList1复选框

    循环绑定数据的两个方法:

    List<string> LIColl = new List<string>();
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    foreach (SPUser user in web.AllUsers)//遍历所有用户
    {
    CheckBoxList1.Items.Add(user.Name);//直接绑定
    LIColl.Add(user.Name);

    //approversCollection.Add(new SPFieldUserValue(web,user.ID,user.LoginName));


    }

    //CheckBoxList1.DataSource = LIColl;//后续绑定
    //CheckBoxList1.DataBind();//后续绑定

    读取

    private static string selval;//读取后放到里面去
    protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
    {

    for (int i = 0; i < CheckBoxList1.Items.Count; i++)
    {
    if (CheckBoxList1.Items[i].Selected)
    {
    selval += CheckBoxList1.Items[i].Text + ";" + selval;
    }
    }


    }

    判断是否选中:

    后台:

    int count = 0;
                    foreach (ListItem item in this.CheckBoxList1.Items)
                    {
                        if (item.Selected)
                        {
                            count++;
                        }
                    }
                    if (count == 0)
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), Guid.NewGuid().ToString(), string.Format("<script>alert('请选择人员!')</script>"));
    
                        return;
                    }
                    else
                    {
                     }

    前台js

    <script type="text/javascript">
      
        function Copy() {
            var dutyflag = 0;
            //ctl00_ctl33_g_5faa55c8_cfe2_4734_9517_ee7dfc9e832d_ctl00_CheckBoxList1_0
            var checkobj = document.getElementById("ctl00_ctl33_g_5faa55c8_cfe2_4734_9517_ee7dfc9e832d_ctl00_CheckBoxList1");
            var checks = checkobj.getElementsByTagName("input");
            for (var n = 0; n < checks.length; n++) {
                if (checks[n].type == "checkbox" && checks[n].checked == true) {
                    dutyflag = 1;
                }
            }
            if (dutyflag == 0) {
                alert("至少要选择1个部门");
                return false;
            }
            else {
                var value = document.getElementById("<%=divnr.ClientID %>").innerHTML;
                var real = value.replace(/<[^>]*>/g, "").replace(/&nbsp;/g, "").replace(/s+/g, "");
                if (real == "") {
                    //alert("real is null");
                    document.getElementById("<%=HiddenFieldnr.ClientID %>").value = "";
                }
                else {
                    //alert("real is not null: "+real)
                    document.getElementById("<%=HiddenFieldnr.ClientID %>").value = value;
                }
                var valu = document.getElementById("<%=divnb.ClientID %>").innerHTML;
                var rea = valu.replace(/<[^>]*>/g, "").replace(/&nbsp;/g, "").replace(/s+/g, "");
                if (rea == "") {
                    //alert("real is null");
                    document.getElementById("<%=HiddenFieldnb.ClientID %>").value = "";
                }
                else {
                    //alert("real is not null: "+real)
                    document.getElementById("<%=HiddenFieldnb.ClientID %>").value = valu;
                }
                return true;
            }
        }
        
    
      
    </script>
     <asp:Button ID="Button1" runat="server" Text="发送" OnClientClick="return Copy()" OnClick="Button1_Click" />
  • 相关阅读:
    24-反转链表
    23-链表中环的入口节点
    22-链表中倒数第k个节点
    21-调整数组顺序使奇数位于偶数前面
    18-删除链表的节点
    17-打印从1到最大的n位数
    16-数值的整数次方
    15-二进制中1的个数
    14-剪绳子
    13-机器人的运动范围
  • 原文地址:https://www.cnblogs.com/914556495wxkj/p/3630527.html
Copyright © 2011-2022 走看看