DataGrid Header Checkbox need way to set after postback
<p>I have a Header CheckBox in a DataGrid on an aspx page and it is used to select all Columns in the DataGrid, DataGrid Items (incliding Checkbox) are bound to SQL data and gets updated when header checkbox is selected via code behind. Problem is after re binding datasource to reflect changed to SQL data, the Header CheckBox is alays unCheck after DataBinding and postback.</p>

<p>Is there a way to toggle the Header CheckBox in code Behind</p>

<p>Data Grid</p>

<pre><code>     &lt;asp:DataGrid ID="Grid" runat="server" PageSize="5" AllowPaging="True" 
       DataKeyField="ID" AutoGenerateColumns="False" CellPadding="4" 
       ForeColor="#333333" GridLines="None" OnPageIndexChanged="Grid_PageIndexChanged"
       OnCancelCommand="Grid_CancelCommand" OnDeleteCommand="Grid_DeleteCommand" 
       OnEditCommand="Grid_EditCommand" OnUpdateCommand="Grid_UpdateCommand"&gt; 
   &lt;Columns&gt; 
       &lt;asp:BoundColumn HeaderText="" DataField="ID" visible="False" &gt; &lt;/asp:BoundColumn&gt; 
       &lt;asp:BoundColumn HeaderText="Process Name" DataField="ProcessName"&gt; &lt;/asp:BoundColumn&gt; 
       &lt;asp:BoundColumn HeaderText="Step" DataField="Order"&gt;  &lt;/asp:BoundColumn&gt; 
       &lt;asp:BoundColumn HeaderText="Instructions" DataField="Instructions"&gt; &lt;/asp:BoundColumn&gt; 
       &lt;asp:TemplateColumn&gt;
           &lt;ItemTemplate&gt;
               &lt;asp:CheckBox ID="cbRows" runat="server"  Checked='&lt;%# DataBinder.Eval(Container.DataItem, "Completed") %&gt;' AutoPostBack="true"  OnCheckedChanged= "Grid_Updatecheckbox" /&gt;
           &lt;/ItemTemplate&gt;
           &lt;HeaderTemplate &gt;
           &lt;%--&lt;asp:Button runat="server" ID="mainCB" onclick="CheckAll" Text="Chk"/&gt;--%&gt;
           &lt;%--&lt;input type="checkbox" id="mainCB"  runat = "server"  onclick="javascript:CheckAll(this);"  /&gt;--%&gt;
           &lt;asp:Checkbox id="mainCB"  AutoPostBack = "true"   runat = "server" OnCheckedChanged="CheckAll"   /&gt;
           &lt;/HeaderTemplate&gt;
           &lt;/asp:TemplateColumn&gt;
       &lt;asp:BoundColumn HeaderText="Completed" DataField="Completed"&gt; &lt;/asp:BoundColumn&gt; 
       &lt;asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" HeaderText="Edit"&gt; &lt;/asp:EditCommandColumn&gt; 
       &lt;asp:ButtonColumn CommandName="Delete" HeaderText="Delete" Text="Delete"&gt; &lt;/asp:ButtonColumn&gt; 
   &lt;/Columns&gt; 
       &lt;FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /&gt; 
       &lt;SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" /&gt; 
       &lt;PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center"  Mode="NumericPages" /&gt; 
       &lt;AlternatingItemStyle BackColor="White" /&gt; 
       &lt;ItemStyle BackColor="#FFFBD6" ForeColor="#333333" /&gt; 
       &lt;HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /&gt; 
   &lt;/asp:DataGrid&gt; 
</code></pre>
