Select All gridview (including paging status)

Source: Internet
Author: User
When creating a project, you often need to use the gridview function to select all. You need to add a checkbox control to control the function. Usually after writing it, because the data volume is small (not paging) the test is normal, but the following error occurs after the gridview page is displayed. How can I write code control? Next, let's take a look.

Error Message

The solution is as follows:
On the previous page, the gridview has a checkbox, as shown below:


Add the following code to the page Javascript script: 1 <SCRIPT type = "text/JavaScript">
2 // select all items
3 function checkall (ocheckbox ){
4 var gridview1 = Document. getelementbyid ("<% = gventerprise. clientid %> ");
5 For (I = 1; I <gridview1.rows. length; I ++ ){
6 OBJ = gridview1.rows [I]. cells [0]. getelementsbytagname ("input") [0];
7 if (OBJ! = NULL ){
8 obj. Checked = ocheckbox. checked;
9}
10}
11}
12 </SCRIPT>

Add the following code to the page gridview control: 1 <asp: gridview id = "gventerprise" runat = "server" autogeneratecolumns = "false" allowpaging = "true">
2 <columns>
3 <asp: templatefield>
4 <itemtemplate>
5 <asp: checkbox id = "input" runat = "server"/>
6 <asp: Label id = "lblid" runat = "server" style = "display: none;" text = '<% # BIND ("ID ") %> '> </ASP: Label>
7 </itemtemplate>
8 9 <asp: checkbox id = "checkbox2" type = "checkbox" onclick = "checkall (this)" runat = "server"/>
10 11 </ASP: templatefield>
12 <asp: boundfield datafield = "classname" headertext = "class"/>
13 <asp: boundfield datafield = "Sno" headertext = "student ID"/>
......
14 </columns>
15 </ASP: gridview>

The background code is no longer demonstrated and its usage is different.

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.