Datagrid|javascript
(i). function
1. JavaScript retrieves the checkbox and realizes the full selection and total elimination function
A checkbox, written in C #, needs to be sent back to the server for execution,
and JavaScript can be implemented on the direct client, more efficient
(ii). Code
1. The main fragment of code in the DataGrid:
<Columns>
<HeaderTemplate>/Header Template code
<asp:checkbox id= "Chkheader" runat= "Server" autopostback= "false"//autopostback is set to false and does not require a postback
></asp:CheckBox>
</HeaderTemplate>
<ItemTemplate>//Item template code
<asp:checkbox id= "Chkitem" runat= "Server" ></asp:CheckBox>
</ItemTemplate>
</Columns>
2. On the page, add:
<script language= "JavaScript" >
function SelectAll (Tempcontrol)
{
Reverse all but the other checkbox in the header template
var Thebox=tempcontrol;
xState=theBox.checked;
elem=thebox.form.elements;
for (i=0;i<elem.length;i++)
if (elem[i].type== "checkbox" && elem[i].id!=thebox.id)
{
if (elem[i].checked!=xstate)
Elem[i].click ();
}
}
</script>
Thank you!