// This is the javascript code. Just copy and paste the code within the script tag
function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal)
{
re = new RegExp(':' + aspCheckBoxID + '$')
for(i = 0; i < Form1.elements.length; i++)
{
elm = document.forms[0].elements[i] if (elm.type == 'checkbox')
{
if (re.test(elm.name)) elm.checked = checkVal
}
}
}
// This is the sample design structure of the datagrid, in only display the checkbox and name
</headertemplate />
|
<asp:datagrid id="dgReciveApp" runat="server" AutoGenerateColumns="False" Width="100%" PageSize="15" AllowPaging="True" DataKeyField="vc_UserName"> <Columns> <asp:TemplateColumn HeaderText="Select All"> <HeaderTemplate> <input ID="chkAll" type="checkbox" onclick="CheckAllDataGridCheckBoxes('chkItem',this.checked)"> Select All</HeaderTemplate> <ItemTemplate> <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0"> <TR> <TD WIDTH="3%" BGCOLOR="#FFFFFF" height="100%"> <table width="100%" height="100%"> <tr valign="top" height="100%"> <td> <asp:CheckBox ID="chkItem" Runat="server"></asp:CheckBox></td> <tr valign="middle" height="100%"> <td valign="middle">
<%# DataBinde.Eval(Container.DataItem,"Name") %> </td> </tr> </table> </TD>
</tr>
</table> | |
</table>
</ItemTemplate> </asp:TemplateColumn> </Columns></asp:datagrid>
Here if u click the header checkbox all datagrid itemtemplate ceckbox are selected
< />
<script language="javascript"></script>