2.0 uses the parent of sender to obtain the current row in the gridview.

Source: Internet
Author: User
Many people in the Forum are asking questions about how to obtain the gridview,
Of course there are several ways to solve this problem:
1. In the rowcommand event, determine the name of the send button control for the request and obtain the required parameters in the current row based on the passed parameters.
2. Set the datakeynames mode in the gridview.
The above implementation is no longer cumbersome.

Today, we will introduce you to the following methods:
Use the parent of the sender of the control event to obtain the cell object, and then obtain the upper-level object of the cell, that is, the row object. Easy!

Put a template column in the third column and put a checkbox. The idea is to set the lable Status of the fourth column as "T" during selection. When the label is deselected, clear lable status ID in column 4

Protected   Void Checkbox#checkedchanged ( Object Sender, eventargs E)
Checkbox chk = (checkbox) sender;

Datacontrolfieldcell DCF = (datacontrolfieldcell) chk. parent;
Gridviewrow gvr = (gridviewrow) DCF. parent;

If (chk. Checked)
Label lab = (Label) gvr. cells [3]. findcontrol ("label1 ");
Lab. Text = "T ";
Label lab = (Label) gvr. cells [3]. findcontrol ("label1 ");
Lab. Text = "";

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: 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.