ImageButton in a GridView
-
I have an ImageButton in the Item Template of the fourth column of a gridview. I am trying to access it in the *.aspx.cs file but am unable to do so. I need this button to pass it as a parameter to a method and have tried multiple routes including this one which seemed like something that should have worked:- (ImageButton)Gridview.FindControl("EditButton"); "EditButton" is the name of the ImageButton Could anyone help me out. Thanks, Sudeep
-
I have an ImageButton in the Item Template of the fourth column of a gridview. I am trying to access it in the *.aspx.cs file but am unable to do so. I need this button to pass it as a parameter to a method and have tried multiple routes including this one which seemed like something that should have worked:- (ImageButton)Gridview.FindControl("EditButton"); "EditButton" is the name of the ImageButton Could anyone help me out. Thanks, Sudeep
When calling a method such as this:
(ImageButton)Gridview.FindControl("EditButton");
you need to tell it which row to get the control from. So it should look like this:(ImageButton)Gridview.Rows[0].FindControl("EditButton");
The number (0) is the index of the row. Alternatively you can get it in the ImageButtons onClick method. In this case, the sender parameter (comes in as an object) is the ImageButton. -
When calling a method such as this:
(ImageButton)Gridview.FindControl("EditButton");
you need to tell it which row to get the control from. So it should look like this:(ImageButton)Gridview.Rows[0].FindControl("EditButton");
The number (0) is the index of the row. Alternatively you can get it in the ImageButtons onClick method. In this case, the sender parameter (comes in as an object) is the ImageButton.Thanks a ton.