Click here to Skip to main content
15,908,673 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more: (untagged)
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
Posted

1 solution

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.
 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900