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!
Example:
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 ";
}
Else
{
Label lab = (Label) gvr. cells [3]. findcontrol ("label1 ");
Lab. Text = "";
}
}