Click here to Skip to main content
15,894,540 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have a checkbox list which the checkboxlist items are populated using a stored procedure. However I added a "Select All" list item to the checkbox list.

How can I disable all other checkbox list items when "Select All" is checked?

ASPX
ASP.NET
<asp:CheckBoxList ID="CheckBoxList1" runat="server" 
Height="80px" Width="500px" AppendDataBoundItems="True" ViewStateMode="Enabled">
<asp:ListItem Selected="True" Text="Select All" Value="Select All"></asp:ListItem>
</asp:CheckBoxList>


ASPX.CS
C#
protected void Page_Load(object sender, EventArgs e)
{


    using (SqlConnection conn = new SqlConnection(dbConn))
    {
        try //Call stored procedure
        {

            SqlCommand cmd = new SqlCommand(spddl, conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            if (!IsPostBack)
            {
                CheckBoxList1.DataSource = ds.Tables[0];
                CheckBoxList1.DataTextField = ds.Tables[0].Columns["ID"].ToString();
                CheckBoxList1.DataBind();



            }
            if (IsPostBack)
            {
                Bind();
            }

        }

        catch (Exception i)
        {
            bool exception = true;
            if (exception == true)
            {
                //txtMessage.Text += e.Message;
            }
        }
    }
}
Posted
Updated 22-Sep-15 2:49am
v2

1 solution

XML
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script>
$(function(){
$("input[type='checkbox']").change(function(){
debugger;
if(($("input[type='checkbox']")[0]).checked) {
                $("input[type='checkbox']").not($("input[type='checkbox']")[0]).attr("disabled","disabled");
                }
else
{
  $("input[type='checkbox']").not($("input[type='checkbox']")[0]).removeAttr("disabled");
}
});
});

</script>
</head>
<body>
  <input type="checkbox" name="selectGroup" value="select All"> Select All<br>
  <input type="checkbox" name="selectGroup" value="select 1">select 1<br>
  <input type="checkbox" name="selectGroup" value="select 2">select 2<br>
  <input type="checkbox" name="selectGroup" value="select 3">select 3<br>
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900