Checkboxlist to get the checkboxindex of the current operation

Source: Internet
Author: User

Previously, checkboxlist was used in the project. To obtain the checkbox information on the server after clicking a checkbox, such as index, it seems that it is not supported. After searching for some methods on the internet, the following describes the solutions for loadpostdata and raisepostdatachangedevent of the overloaded checkboxlist.

Steps:

1. Rewrite loadpostdata and raisepostdatachangedevent of checkboxlist (for details, see the followingCodeNote)

2. From bulletedlisteventargs in your own event, you can get the index of the current click.

1
2   Public Class Mycheckboxlist: checkboxlist
3 {
4 Private Int _ Currentitemindex;
5
6 Protected Override Bool Loadpostdata ( String Postdatakey, system. Collections. Specialized. namevaluecollection postcollection)
7 {
8
9 Bool Retval = Base . Loadpostdata (postdatakey, postcollection );
10
11 If (Retval)
12 {
13 // This function is transferred to every checkbox, that is, the number of calls to this function is the number of subcheckboxes it owns.
14 // The value is obtained only when the return value is true,
15 // Otherwise, the index is always the largest.
16   This . _ Currentitemindex = Int . Parse (postdatakey. substring ( This . Uniqueid. Length + 1 ), Cultureinfo. invariantculture );
17 }
18
19 Return Retval;
20 }
21
22 Protected Override Void Raisepostdatachangedevent ()
23 {
24 If ( This . Autopostback && ! This . Page. ispostbackeventcontrolregistered)
25 {
26 This . Page. autopostbackcontrol = This ;
27 If ( This . Causesvalidation)
28 {
29 This . Page. Validate ( This . Validationgroup );
30 }
31 }
32 This . Onselectedindexchanged ( New Bulletedlisteventargs ( This . _ Currentitemindex ));
33 }
34 }
35  

 

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.