Using sender's parent to get the current line in the GridView (get the value of the GridView) _ Practical Tips

Source: Internet
Author: User


There are several ways to get the GridView line:

In the 1 plus Rowcommand event, determine the name of the Issued button control for the request, and according to the parameters passed, get the parameters we need in the current row.
2 GridView Set DataKeyNames mode.

The above methods are no longer burdensome.

Today to introduce one of the most convenient, but also the most satisfying day-to-day thinking of a good way:
The sender parent of the control event is used to get the cell object, and then the parent object of the cell, which is the row object. It's easy!

Examples are as follows:
In the third column, put a template column, put a checkbox, the idea is to set the fourth column lable status identified as "T", when unchecked, the fourth column lable status identity empty

Click the checkbox directly in the template column and add the following code.

Copy Code code as follows:

protected void Checkbox1_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";
}
Else
{
Label Lab = (label) GVR. CELLS[3]. FindControl ("Label1");
Lab. Text = "";
}
}

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.