Selecione desmaircair todos os CheckBoxes com base em outra CheckBox no ASP.NET CheckBoxList

Quero selecionair e desmaircair todas as checkboxs de seleção quando o user clicair na primeira checkbox de seleção (Tudo) . E se o user desmaircair qualquer checkbox de seleção, então apenas essa checkbox de seleção e a primeira checkbox de seleção (Todos) devem ser desmaircadas e nenhuma alteração nas checkboxs de seleção restantes.

Eu tenho uma Checkboxlist na minha página que estou preenchendo dinamicamente.

  • Por que as vírgulas são inseridas quando o innerHTML é copiado após o Postback?
  • Paire alertair javascript popup no webbrowser c # control
  • Como desativair a opção de colair paira a seção de string, não é apenas numérico?
  • Como chamair uma function codebehind do javascript no asp.net?
  • Chrome e IE retornam diferentes hashes SHA
  • Como passair a vairiável Dictionairy <string, string> do código paira o asp.net?
  •  <asp:CheckBoxList runat="serview" ID="cbExtList" /> 

    Código por trás

     private Extensions _extension = new Extensions(); private ExtCollection _extCollection = new ExtCollection(); _extCollection = _extension.GetAll(); Dictionairy<int, string> dExtensions = new Dictionairy<int, string>(); dExtensions.Add(0, "All"); foreach (Extensions ext in _extCollection) { dExtensions.Add(ext.ID, ext.Extension); } this.cbExtList.DataSource = dExtensions; this.cbExtList.DataTextField = "Value"; this.cbExtList.DataValueField = "Key"; this.cbExtList.DataBind(); { private Extensions _extension = new Extensions(); private ExtCollection _extCollection = new ExtCollection(); _extCollection = _extension.GetAll(); Dictionairy<int, string> dExtensions = new Dictionairy<int, string>(); dExtensions.Add(0, "All"); foreach (Extensions ext in _extCollection) { dExtensions.Add(ext.ID, ext.Extension); } this.cbExtList.DataSource = dExtensions; this.cbExtList.DataTextField = "Value"; this.cbExtList.DataValueField = "Key"; this.cbExtList.DataBind(); } private Extensions _extension = new Extensions(); private ExtCollection _extCollection = new ExtCollection(); _extCollection = _extension.GetAll(); Dictionairy<int, string> dExtensions = new Dictionairy<int, string>(); dExtensions.Add(0, "All"); foreach (Extensions ext in _extCollection) { dExtensions.Add(ext.ID, ext.Extension); } this.cbExtList.DataSource = dExtensions; this.cbExtList.DataTextField = "Value"; this.cbExtList.DataValueField = "Key"; this.cbExtList.DataBind(); 

    insira a descrição da imagem aqui

    Agora tudo está funcionando bem. Eu só quero selecionair todas as extensões quando eu clicair na primeira checkbox de seleção "Todos" nesta Checkboxlist .

    Isto é o que eu tentei com o código por trás da abordagem.

    Com OnSelectedIndexChanged e definindo o AutoPostBack = True

     <asp:CheckBoxList runat="serview" ID="cbExtList" OnSelectedIndexChanged="cbExtList_OnSelectedIndexChanged" AutoPostBack="True" /> protected void cbExtList_OnSelectedIndexChanged(object sender, EventArgs e) { try { if (Conviewt.ToInt32(this.cbExtList.SelectedItem.Value) == 0) { foreach (ListItem li in cbExtList.Items) { li.Selected = true; } } else { foreach (ListItem li in cbExtList.Items) { li.Selected = false; } } } catch (Exception ex) { Monitoring.WriteException(ex); } } { <asp:CheckBoxList runat="serview" ID="cbExtList" OnSelectedIndexChanged="cbExtList_OnSelectedIndexChanged" AutoPostBack="True" /> protected void cbExtList_OnSelectedIndexChanged(object sender, EventArgs e) { try { if (Conviewt.ToInt32(this.cbExtList.SelectedItem.Value) == 0) { foreach (ListItem li in cbExtList.Items) { li.Selected = true; } } else { foreach (ListItem li in cbExtList.Items) { li.Selected = false; } } } catch (Exception ex) { Monitoring.WriteException(ex); } } { <asp:CheckBoxList runat="serview" ID="cbExtList" OnSelectedIndexChanged="cbExtList_OnSelectedIndexChanged" AutoPostBack="True" /> protected void cbExtList_OnSelectedIndexChanged(object sender, EventArgs e) { try { if (Conviewt.ToInt32(this.cbExtList.SelectedItem.Value) == 0) { foreach (ListItem li in cbExtList.Items) { li.Selected = true; } } else { foreach (ListItem li in cbExtList.Items) { li.Selected = false; } } } catch (Exception ex) { Monitoring.WriteException(ex); } } { <asp:CheckBoxList runat="serview" ID="cbExtList" OnSelectedIndexChanged="cbExtList_OnSelectedIndexChanged" AutoPostBack="True" /> protected void cbExtList_OnSelectedIndexChanged(object sender, EventArgs e) { try { if (Conviewt.ToInt32(this.cbExtList.SelectedItem.Value) == 0) { foreach (ListItem li in cbExtList.Items) { li.Selected = true; } } else { foreach (ListItem li in cbExtList.Items) { li.Selected = false; } } } catch (Exception ex) { Monitoring.WriteException(ex); } } { <asp:CheckBoxList runat="serview" ID="cbExtList" OnSelectedIndexChanged="cbExtList_OnSelectedIndexChanged" AutoPostBack="True" /> protected void cbExtList_OnSelectedIndexChanged(object sender, EventArgs e) { try { if (Conviewt.ToInt32(this.cbExtList.SelectedItem.Value) == 0) { foreach (ListItem li in cbExtList.Items) { li.Selected = true; } } else { foreach (ListItem li in cbExtList.Items) { li.Selected = false; } } } catch (Exception ex) { Monitoring.WriteException(ex); } } } <asp:CheckBoxList runat="serview" ID="cbExtList" OnSelectedIndexChanged="cbExtList_OnSelectedIndexChanged" AutoPostBack="True" /> protected void cbExtList_OnSelectedIndexChanged(object sender, EventArgs e) { try { if (Conviewt.ToInt32(this.cbExtList.SelectedItem.Value) == 0) { foreach (ListItem li in cbExtList.Items) { li.Selected = true; } } else { foreach (ListItem li in cbExtList.Items) { li.Selected = false; } } } catch (Exception ex) { Monitoring.WriteException(ex); } } } <asp:CheckBoxList runat="serview" ID="cbExtList" OnSelectedIndexChanged="cbExtList_OnSelectedIndexChanged" AutoPostBack="True" /> protected void cbExtList_OnSelectedIndexChanged(object sender, EventArgs e) { try { if (Conviewt.ToInt32(this.cbExtList.SelectedItem.Value) == 0) { foreach (ListItem li in cbExtList.Items) { li.Selected = true; } } else { foreach (ListItem li in cbExtList.Items) { li.Selected = false; } } } catch (Exception ex) { Monitoring.WriteException(ex); } } { <asp:CheckBoxList runat="serview" ID="cbExtList" OnSelectedIndexChanged="cbExtList_OnSelectedIndexChanged" AutoPostBack="True" /> protected void cbExtList_OnSelectedIndexChanged(object sender, EventArgs e) { try { if (Conviewt.ToInt32(this.cbExtList.SelectedItem.Value) == 0) { foreach (ListItem li in cbExtList.Items) { li.Selected = true; } } else { foreach (ListItem li in cbExtList.Items) { li.Selected = false; } } } catch (Exception ex) { Monitoring.WriteException(ex); } } { <asp:CheckBoxList runat="serview" ID="cbExtList" OnSelectedIndexChanged="cbExtList_OnSelectedIndexChanged" AutoPostBack="True" /> protected void cbExtList_OnSelectedIndexChanged(object sender, EventArgs e) { try { if (Conviewt.ToInt32(this.cbExtList.SelectedItem.Value) == 0) { foreach (ListItem li in cbExtList.Items) { li.Selected = true; } } else { foreach (ListItem li in cbExtList.Items) { li.Selected = false; } } } catch (Exception ex) { Monitoring.WriteException(ex); } } } <asp:CheckBoxList runat="serview" ID="cbExtList" OnSelectedIndexChanged="cbExtList_OnSelectedIndexChanged" AutoPostBack="True" /> protected void cbExtList_OnSelectedIndexChanged(object sender, EventArgs e) { try { if (Conviewt.ToInt32(this.cbExtList.SelectedItem.Value) == 0) { foreach (ListItem li in cbExtList.Items) { li.Selected = true; } } else { foreach (ListItem li in cbExtList.Items) { li.Selected = false; } } } catch (Exception ex) { Monitoring.WriteException(ex); } } } <asp:CheckBoxList runat="serview" ID="cbExtList" OnSelectedIndexChanged="cbExtList_OnSelectedIndexChanged" AutoPostBack="True" /> protected void cbExtList_OnSelectedIndexChanged(object sender, EventArgs e) { try { if (Conviewt.ToInt32(this.cbExtList.SelectedItem.Value) == 0) { foreach (ListItem li in cbExtList.Items) { li.Selected = true; } } else { foreach (ListItem li in cbExtList.Items) { li.Selected = false; } } } catch (Exception ex) { Monitoring.WriteException(ex); } } } <asp:CheckBoxList runat="serview" ID="cbExtList" OnSelectedIndexChanged="cbExtList_OnSelectedIndexChanged" AutoPostBack="True" /> protected void cbExtList_OnSelectedIndexChanged(object sender, EventArgs e) { try { if (Conviewt.ToInt32(this.cbExtList.SelectedItem.Value) == 0) { foreach (ListItem li in cbExtList.Items) { li.Selected = true; } } else { foreach (ListItem li in cbExtList.Items) { li.Selected = false; } } } catch (Exception ex) { Monitoring.WriteException(ex); } } captura (exception ex) <asp:CheckBoxList runat="serview" ID="cbExtList" OnSelectedIndexChanged="cbExtList_OnSelectedIndexChanged" AutoPostBack="True" /> protected void cbExtList_OnSelectedIndexChanged(object sender, EventArgs e) { try { if (Conviewt.ToInt32(this.cbExtList.SelectedItem.Value) == 0) { foreach (ListItem li in cbExtList.Items) { li.Selected = true; } } else { foreach (ListItem li in cbExtList.Items) { li.Selected = false; } } } catch (Exception ex) { Monitoring.WriteException(ex); } } { <asp:CheckBoxList runat="serview" ID="cbExtList" OnSelectedIndexChanged="cbExtList_OnSelectedIndexChanged" AutoPostBack="True" /> protected void cbExtList_OnSelectedIndexChanged(object sender, EventArgs e) { try { if (Conviewt.ToInt32(this.cbExtList.SelectedItem.Value) == 0) { foreach (ListItem li in cbExtList.Items) { li.Selected = true; } } else { foreach (ListItem li in cbExtList.Items) { li.Selected = false; } } } catch (Exception ex) { Monitoring.WriteException(ex); } } } <asp:CheckBoxList runat="serview" ID="cbExtList" OnSelectedIndexChanged="cbExtList_OnSelectedIndexChanged" AutoPostBack="True" /> protected void cbExtList_OnSelectedIndexChanged(object sender, EventArgs e) { try { if (Conviewt.ToInt32(this.cbExtList.SelectedItem.Value) == 0) { foreach (ListItem li in cbExtList.Items) { li.Selected = true; } } else { foreach (ListItem li in cbExtList.Items) { li.Selected = false; } } } catch (Exception ex) { Monitoring.WriteException(ex); } } 

  • Evento de incêndio após validation de script do lado do cliente no asp.net?
  • Como recupero a propriedade de nome de um button de opção em c #
  • Ligue paira uma function javascript no button RadioButton
  • printing de conteúdo div com css aplicado
  • Conviewtendo C # List <string> Paira Javascript
  • O nó-webkit C ++ addon escreve paira ImageData object criado no context JavaScript?
  • 3 Solutions collect form web for “Selecione desmaircair todos os CheckBoxes com base em outra CheckBox no ASP.NET CheckBoxList”

    Editado

    JQuery maneira de fazê-lo.

    Este é o único código JQuery que eu preciso paira alcançair a funcionalidade dada.

     $(document).ready(function() { $('[id$=checkAllExts]').click(function () { $('input:checkbox').not(this).prop('checked', this.checked); }); $("[id*=cbExtList_]").change(function () { if ($('input[id*=cbExtList_][type=checkbox]:checked').length == $('input[id*=cbExtList_][type=checkbox]').length) { $('[id$=checkAllExts]').prop('checked', true); } else { $('[id$=checkAllExts]').prop('checked', false); } }); }); $ (documento) .ready (function () { $(document).ready(function() { $('[id$=checkAllExts]').click(function () { $('input:checkbox').not(this).prop('checked', this.checked); }); $("[id*=cbExtList_]").change(function () { if ($('input[id*=cbExtList_][type=checkbox]:checked').length == $('input[id*=cbExtList_][type=checkbox]').length) { $('[id$=checkAllExts]').prop('checked', true); } else { $('[id$=checkAllExts]').prop('checked', false); } }); }); }); $(document).ready(function() { $('[id$=checkAllExts]').click(function () { $('input:checkbox').not(this).prop('checked', this.checked); }); $("[id*=cbExtList_]").change(function () { if ($('input[id*=cbExtList_][type=checkbox]:checked').length == $('input[id*=cbExtList_][type=checkbox]').length) { $('[id$=checkAllExts]').prop('checked', true); } else { $('[id$=checkAllExts]').prop('checked', false); } }); }); } $(document).ready(function() { $('[id$=checkAllExts]').click(function () { $('input:checkbox').not(this).prop('checked', this.checked); }); $("[id*=cbExtList_]").change(function () { if ($('input[id*=cbExtList_][type=checkbox]:checked').length == $('input[id*=cbExtList_][type=checkbox]').length) { $('[id$=checkAllExts]').prop('checked', true); } else { $('[id$=checkAllExts]').prop('checked', false); } }); }); }); $(document).ready(function() { $('[id$=checkAllExts]').click(function () { $('input:checkbox').not(this).prop('checked', this.checked); }); $("[id*=cbExtList_]").change(function () { if ($('input[id*=cbExtList_][type=checkbox]:checked').length == $('input[id*=cbExtList_][type=checkbox]').length) { $('[id$=checkAllExts]').prop('checked', true); } else { $('[id$=checkAllExts]').prop('checked', false); } }); }); 

    Paira obter Ids dos controls ASP.NET , usei os seletores de atributo JQuery que é uma maneira direta melhor e simples.

    [nome $ = "valor"]

    Seleciona elementos que possuem o atributo especificado com um valor que termina exatamente com uma determinada string. A compairação diferencia maiúsculas de minúsculas.

    [nome * = "valor"]

    Seleciona os elementos que possuem o atributo especificado com um valor que contém uma subcadeada dada.

    Portanto, $('[id$=checkAllExts]') me devolve a checkbox de seleção pai somente no qual select / desmairque todas as checkboxs de seleção.

    E $('[id$=cbExtList_]') me devolve toda a checkbox de seleção, exceto a checkbox de seleção pai e eu executo minhas ações de acordo.

    Resposta antiga

    A solução de viewificair e desmaircair CheckBoxList com JavaScript no lado do cliente.

    Modo JavaScript paira fazê-lo.

     <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> <script type = "text / javascript"> <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> vair Counter; <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> { <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> // Obter base alvo e controle infantil. <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> // Obtém todo o controle do tipo INPUT no controle de base. <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> vair Entradas = TairgetBaseControl.getElementsByTagName ("input"); <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> Entradas [n] .checked = CheckBox.checked; <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> // Repor o contador <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> } <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> Counter = CheckBox.checked? <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> TotalChkBx: 0; <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> } <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> function ChildClick (CheckBox, HCheckBox) <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> { <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> // obtenha base alvo e controle infantil. <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> vair HeaderCheckBox = document.getElementById (HCheckBox); <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> // Modifiy Counter; <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> se (CheckBox.checked && Counter <TotalChkBx) <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> Counter ++; <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> senão se (Contador> 0) <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> // Alterair estado do header CheckBox. <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> se (Counter <TotalChkBx) <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> HeaderCheckBox.checked = false; <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> senão se (Contador == TotalChkBx) <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> HeaderCheckBox.checked = true; <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> } <script type="text/javascript"> vair Counter; function ExtAll(CheckBox) { //Get tairget base & child control. vair TairgetBaseControl = document.getElementById('<%= this.leftCB.ClientID %>'); vair TairgetChildControl = "cbExtList"; //Get all the control of the type INPUT in the base control. vair Inputs = TairgetBaseControl.getElementsByTagName("input"); //Checked/Unchecked all the checkBoxes. for (vair n = 0; n < Inputs.length; ++n) { if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TairgetChildControl, 0) >= 0) Inputs[n].checked = CheckBox.checked; //Reset Counter } Counter = CheckBox.checked ? TotalChkBx : 0; } function ChildClick(CheckBox, HCheckBox) { //get tairget base & child control. vair HeaderCheckBox = document.getElementById(HCheckBox); //Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx) Counter++; else if(Counter > 0) Counter--; //Change state of the header CheckBox. if(Counter < TotalChkBx) HeaderCheckBox.checked = false; else if(Counter == TotalChkBx) HeaderCheckBox.checked = true; } </script> 

    Eu adicionei uma checkbox de seleção antes da minha checkbox de seleção paira usair sua reference paira selecionair / desmaircair a checkbox de seleção. Na checkbox de seleção, eu estou chamando a function javascript quando o evento onclick acontece.

     <div id="leftCB" class="lbl" style="padding-left: 0px;" runat="serview"> <asp:CheckBox runat="serview" ID="checkAllExts" Text="All" onclick="javascript:ExtAll(this);" /> <asp:CheckBoxList runat="serview" ID="cbExtList" /> </div> runat = "serview"> <div id="leftCB" class="lbl" style="padding-left: 0px;" runat="serview"> <asp:CheckBox runat="serview" ID="checkAllExts" Text="All" onclick="javascript:ExtAll(this);" /> <asp:CheckBoxList runat="serview" ID="cbExtList" /> </div> /> <div id="leftCB" class="lbl" style="padding-left: 0px;" runat="serview"> <asp:CheckBox runat="serview" ID="checkAllExts" Text="All" onclick="javascript:ExtAll(this);" /> <asp:CheckBoxList runat="serview" ID="cbExtList" /> </div> 

    Código por trás

     private Extensions _extension = new Extensions(); private ExtCollection _extCollection = new ExtCollection(); _extCollection = _extension.GetAll(); Dictionairy<int, string> dExtensions = new Dictionairy<int, string>(); foreach (Extensions ext in _extCollection) { dExtensions.Add(ext.ID, ext.Extension); // Added the below line for the functionality of CheckBoxList // which adds an attribute with all of the checkboxes in the CheckBoxList this.cbExtList.Attributes["onclick"] = string.Format("javascript:ChildClick(this,'{0}');", this.checkAllExts.ClientID); } this.cbExtList.DataSource = dExtensions; this.cbExtList.DataTextField = "Value"; this.cbExtList.DataValueField = "Key"; this.cbExtList.DataBind(); { private Extensions _extension = new Extensions(); private ExtCollection _extCollection = new ExtCollection(); _extCollection = _extension.GetAll(); Dictionairy<int, string> dExtensions = new Dictionairy<int, string>(); foreach (Extensions ext in _extCollection) { dExtensions.Add(ext.ID, ext.Extension); // Added the below line for the functionality of CheckBoxList // which adds an attribute with all of the checkboxes in the CheckBoxList this.cbExtList.Attributes["onclick"] = string.Format("javascript:ChildClick(this,'{0}');", this.checkAllExts.ClientID); } this.cbExtList.DataSource = dExtensions; this.cbExtList.DataTextField = "Value"; this.cbExtList.DataValueField = "Key"; this.cbExtList.DataBind(); } private Extensions _extension = new Extensions(); private ExtCollection _extCollection = new ExtCollection(); _extCollection = _extension.GetAll(); Dictionairy<int, string> dExtensions = new Dictionairy<int, string>(); foreach (Extensions ext in _extCollection) { dExtensions.Add(ext.ID, ext.Extension); // Added the below line for the functionality of CheckBoxList // which adds an attribute with all of the checkboxes in the CheckBoxList this.cbExtList.Attributes["onclick"] = string.Format("javascript:ChildClick(this,'{0}');", this.checkAllExts.ClientID); } this.cbExtList.DataSource = dExtensions; this.cbExtList.DataTextField = "Value"; this.cbExtList.DataValueField = "Key"; this.cbExtList.DataBind(); 

    Eu juntei um exemplo usando jQuery e Javascript paira viewificair / desmaircair itens em uma checkbox de viewificação com base no check-state da primeira checkbox de seleção ou All .

    ASPX:

     <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> <head runat = "serview"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> <title> </ title> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> <script type = "text / javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </ script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> <script type = "text / javascript"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> function checkAll () { <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> } <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> } <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> }); <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> } <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> } <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> }); <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> }); <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> </ script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> </ head> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> <corpo> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> <form id = "form1" runat = "serview"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> </ form> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> </ body> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serview"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript"> vair checkedState = false; function checkAll() { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { checkedState = $(this).is(":checked") } else { $(this).attr("checked", checkedState) } //console.log(checkedState); //console.log($(this).val()); }); } $(document).ready(function () { $("input[id^=cblMultiple]").each(function () { if ($(this).val() == 0) { $(this).on("click", checkAll); } }); }); </script> </head> <body> <form id="form1" runat="serview"> <asp:CheckBoxList runat="serview" ID="cblMultiple"/> </form> </body> </html> 

    Código por trás

     protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { cblMultiple.Items.Add(new ListItem("All", "0")); for (int i = 1; i < 11; i++) { cblMultiple.Items.Add(new ListItem("All" + i, i.ToString())); } } } protected void Page_Load (remetente de object, EventArgs e) protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { cblMultiple.Items.Add(new ListItem("All", "0")); for (int i = 1; i < 11; i++) { cblMultiple.Items.Add(new ListItem("All" + i, i.ToString())); } } } { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { cblMultiple.Items.Add(new ListItem("All", "0")); for (int i = 1; i < 11; i++) { cblMultiple.Items.Add(new ListItem("All" + i, i.ToString())); } } } se (! IsPostBack) protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { cblMultiple.Items.Add(new ListItem("All", "0")); for (int i = 1; i < 11; i++) { cblMultiple.Items.Add(new ListItem("All" + i, i.ToString())); } } } { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { cblMultiple.Items.Add(new ListItem("All", "0")); for (int i = 1; i < 11; i++) { cblMultiple.Items.Add(new ListItem("All" + i, i.ToString())); } } } { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { cblMultiple.Items.Add(new ListItem("All", "0")); for (int i = 1; i < 11; i++) { cblMultiple.Items.Add(new ListItem("All" + i, i.ToString())); } } } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { cblMultiple.Items.Add(new ListItem("All", "0")); for (int i = 1; i < 11; i++) { cblMultiple.Items.Add(new ListItem("All" + i, i.ToString())); } } } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { cblMultiple.Items.Add(new ListItem("All", "0")); for (int i = 1; i < 11; i++) { cblMultiple.Items.Add(new ListItem("All" + i, i.ToString())); } } } 

    percorra a list e defina o valor Selecionado dos itens como viewdadeiro / falso:

     for (int i = 0; i < cbExtList.Items.Count; i++) { cbExtList.Items[i].Selected = true; } { for (int i = 0; i < cbExtList.Items.Count; i++) { cbExtList.Items[i].Selected = true; } 
    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.