Add a checkbox column to the JavaScript implementation datagrid

Source: Internet
Author: User
Tags header
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!



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.