Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am having datalist which is having list of checkboxes. One of the datalist item is ALL. If user check that ALL(checkbox), then I want to check all remaining checkboxes or disable all the remaining checkboxes.

I am using the below given code, but it is not working. Tell me some efficient way to do this.
C#
protected void chkFacilityChanged(object sender,   EventArgs e)
    { 
        foreach (DataListItem rptItem in rptFactility.Items)
        {
           CheckBox allchk = (CheckBox)rptItem.FindControl("chkFacility").ToString();
          string  facilityCode = rptItem.FindControl("lblFacilityCode").ToString();
           if ( facilityCode.Text.ToString() = "0"   && allchk.checked)
             {                 
                allchk1.Checked = true;
               //rptItem1.Enabled = false;
                }
               return;
            }
        }
}

OR
C#
protected void chkFacilityChanged(object sender,   EventArgs e)
    {
        foreach (DataListItem rptItem in rptFactility.Items)
        {
           CheckBox allchk = (CheckBox)rptItem.FindControl("chkFacility").ToString();

          string  facilityCode = rptItem.FindControl("lblFacilityCode").ToString();
           if ( facilityCode.Text.ToString() = "0"   && allchk.checked)
             {
               foreach (DataListItem rptItem1 in rptFactility.Items)
        {
                CheckBox allchk1 = (CheckBox)rptItem.FindControl("chkFacility").ToString();

                allchk1.Checked1 = true;
               //rptItem1.Enabled = false;
                }
               return;
            }
        }
}
Posted
Updated 6-Sep-10 8:35am
v2

Tell me some efficient way to do this.
Do it client side, using JavaScript.

You would need to loop though the Datalist and Select All or Disable all the items one by one.
 
Share this answer
 
Comments
raju melveetilpurayil 6-Sep-10 18:55pm    
I am also support this. do with JavaScript.
hello,

Here is a good example Check uncheck all checkboxes in Gridview[^]. Just replace the GridView id with your DataList control ID.
 
Share this answer
 
hi,there
you can do it by jquery.
container refer to a jquery object(your datalist object).

var checkboxes = container.find("input[type='checkbox']");
then you can loop and operate it in client side.
 
Share this answer
 
You can implement the same easily using Java script. The column containing check-box would be having id typically of the format 'dgGrid__cntrlXX_chkFacility', hence you can easily parse through the list of check-boxes. You would have to just trigger the Javascript onclick of the check-box.
 
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