The selection function of the gridview control. The Code implements full selection, inverse selection, and cancellation of the checkbox control.

Source: Internet
Author: User

When it comes to the Selection Function of the gridview control, it must be closely related to the checkbox control, which is beyond doubt. The most important thing to select is to facilitate user operations, such as batch deletion.

The gridview is bound to the background database, and the first column is bound to the checkbox Selection control. The ID is "deletethis", which is easy to choose. The bound code is between the gridview <columns> </columns>. The front-end sample code is as follows:

<Asp: templatefield controlstyle-width = "30" headertext = "select" runat = "server"> <itemtemplate> <asp: checkbox id = "deletethis" runat = "server"/> </itemtemplate> <controlstyle width = "30px"> </controlstyle> </ASP: templatefield>

For better understanding and explanation, upload the overall design interface of the front-end as follows:

In the lower-left corner of the page, you can use the full selection box, reverse selection box, and cancel button to control the first column selection box of the gridview. The front-end design code example is as follows:

<Table border = "0" cellspacing = "0" cellpadding = "1" style = "width: 100%;"> <tr> <TD style = "width: 1px "> </TD> <TD align =" Left "> <B> select: </B> <asp: checkbox id = "chkball" runat = "server" text = "select all" width = "47px" autopostback = "true" oncheckedchanged = "chkball_checkedchanged"/> <asp: checkbox id = "chkbuncheck" runat = "server" text = "invert" width = "47px" autopostback = "true" oncheckedchanged = "chkbuncheck_checkedchanged"/> <asp: button id = "btncancel" runat = "server" text = "cancel" width = "47px" onclick = "btncancel_click"/> </TD> <TD align = "right"> <asp: button id = "btndelete" runat = "server" text = "delete" width = "47px" onclick = "btndelete_click"/> </TD> <TD style = "width: 1px "> </TD> </tr> </table> <br/>

Front-end design for full selection and invert Selection

In fact, there are various implementation methods for the selection function today, such as JS and jquery, and you will not be able to choose either of them, what we need to do is to implement the functions required for the page based on our language capabilities. In our spare time, we can consider other methods...

If you want to learn a language well, you have to constantly contact, learn, stick to, and think.

If you don't talk nonsense, let's get down to the point. The code for implementing the selection function in the CS background code is as follows:

/// <Summary> /// select all /// </Summary> /// <Param name = "sender"> </param> /// <Param name =" E "> </param> protected void chkball_checkedchanged (Object sender, eventargs e) {for (INT I = 0; I <gridview. rows. count; I ++) {checkbox CHB = (checkbox) gridview. rows [I]. findcontrol ("deletethis"); If (chkball. checked) {CHB. checked = true;} else {CHB. checked = false ;}} chkbuncheck. checked = false ;} /// <summary> /// reselect /// </Summary> /// <Param name = "sender"> </param> /// <Param name =" E "> </param> protected void chkbuncheck_checkedchanged (Object sender, eventargs e) {for (INT I = 0; I <gridview. rows. count; I ++) {checkbox CHB = (checkbox) gridview. rows [I]. findcontrol ("deletethis"); If (CHB. checked = true) {CHB. checked = false;} else {CHB. checked = true ;}} chkball. checked = false ;} /// <summary> /// cancel /// </Summary> /// <Param name = "sender"> </param> /// <Param name =" E "> </param> protected void btncancel_click (Object sender, eventargs e) {chkball. checked = false; chkbuncheck. checked = false; For (INT I = 0; I <gridview. rows. count; I ++) {checkbox CHB = (checkbox) gridview. rows [I]. findcontrol ("deletethis"); CHB. checked = false ;}}

The code is provided to you. If you need it, make a good understanding. If you have any shortcomings, please give your comments more...

For reference only !!!

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.