Dropdownlist placed in the GridView to get the row number of the GridView

Source: Internet
Author: User

In the template column of the GridView or DataGrid Control, place the DropDownList control. By changing the value of the DropDownList control, you can change other information of this row in the GridView.

Specific implementation methods:

Code
1 protected void Drpd_SelectedIndexChanged (object sender, EventArgs e)
2 {
3
4 DropDownList drp = sender as DropDownList; // The DropDownList that triggers the event
5 GridViewRow row = drp. NamingContainer as GridViewRow; // The current row of the GridView instantly contains the row information in the container where the dropdownlist is located.
6 row. Style. Add (HtmlTextWriterStyle. BackgroundColor, drp. SelectedValue );
7 Response. Write (row. RowIndex + 1); // obtain the row number of the row selected in the dropdownlist.
8 // Response. Write (String. Format ("select row {0}", row. RowIndex + 1 ));
9 DropDownList ddlClass = (DropDownList) sender;
10 string ClassID = ddlClass. SelectedValue. ToString (); // obtain the selected value of Dropdownlist
11 // Response. Write (ClassID );
12}
13

Obtain the row number under the SelectedIndexChanged event of dropdownlist.

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.