How to mark checked to all items of a checkboxlist in GridView item template?
<p>Hi i am using the selectall function but it selects all my checkboxlist items in the gridview.</p>

<p>sample code:</p>

<pre><code>&lt;script type="text/javascript"&gt;
function SelectAll(CheckBoxControl) 
{
  if (CheckBoxControl.checked == true) 
  {
    var i;
    for (i=0; i &lt; document.forms[0].elements.length; i++) 
    {
      if ((document.forms[0].elements[i].type == 'checkbox') &amp;&amp; 
         (document.forms[0].elements[i].name.indexOf('ChoiceGrid') &gt; -1)) 
      {
        if(document.forms[0].elements[i].disabled)
        {
          document.forms[0].elements[i].checked = false;
        }
        else
        {
          document.forms[0].elements[i].checked = true;
          document.forms[0].elements[i].disabled= true;
        }
      }
    }
  } 
  else 
  {
    var i;
    for (i=0; i &lt; document.forms[0].elements.length; i++) 
    {
      if ((document.forms[0].elements[i].type == 'checkbox') &amp;&amp; 
          (document.forms[0].elements[i].name.indexOf('ChoiceGrid'))) 
      {
        document.forms[0].elements[i].checked = false;
        document.forms[0].elements[i].disabled= false;
      }
    }
  }
}
&lt;/script&gt;
</code></pre>

<p>I am using a input checkbox, it works but i just want to only select the "above" items and not all items in the gridview.</p>

<p>design:</p>

<pre><code>&lt;asp:GridView ID="ChoiceGrid" GridLines="None" runat="server" AutoGenerateColumns="False"&gt;
    &lt;Columns&gt;
        &lt;asp:BoundField DataField="QnNum"&gt;
            &lt;ItemStyle VerticalAlign="Top" Width="50px" /&gt;
        &lt;/asp:BoundField&gt;
        &lt;asp:TemplateField&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:Label ID="Question" runat="server" Text='&lt;%# Bind("Questions")%&gt;'&gt;&lt;/asp:Label&gt;
                &lt;asp:CheckBoxList ID="ChoiceQuestions" runat="server" DataSource='&lt;%# Bind("CheckBox")%&gt;'&gt; &lt;%-- OnSelectedIndexChanged="ChoiceQuestions_SelectedIndexChanged" AutoPostBack="True"--%&gt;
                &lt;/asp:CheckBoxList&gt;&lt;asp:Label ID="Label1" runat="server" width="1px"&gt;&lt;/asp:Label&gt;&lt;input type="checkbox" id="all" value="NIL" onclick="SelectAll(this)"&gt;All of the above&lt;br /&gt;
                &lt;br /&gt;
            &lt;/ItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
    &lt;/Columns&gt;
    &lt;/asp:GridView&gt;
</code></pre>
