Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we find the control in the row command of grid view?

How can I find the control in the row command of grid view?

like image 251
hardeep Avatar asked Feb 07 '13 10:02

hardeep


3 Answers

Actually there is no Row in GridViewCommandEventArgs, so you will need to get the row from the command source naming container

GridViewRow row = (GridViewRow)(((Control)e.CommandSource).NamingContainer);

then you will be able to use

TextBox myTextBox = row.FindControl("MyTextBoxId") as TextBox;

Hope this helps!

like image 104
Vasil Trifonov Avatar answered Oct 20 '22 19:10

Vasil Trifonov


if your using LinkButton

 LinkButton ctrl = e.CommandSource as LinkButton;
   if (ctrl != null)
    {
        GridViewRow row = ctrl.Parent.NamingContainer as GridViewRow;
        TextBox txtDescription = (TextBox)row.FindControl("txtDescription");
    }
like image 44
Krishna shidnekoppa Avatar answered Oct 20 '22 20:10

Krishna shidnekoppa


GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);

Label lblProdId = (Label)row.FindControl(“lblproductId”);
like image 20
0nly.Phani Avatar answered Oct 20 '22 20:10

0nly.Phani