As mentioned in @mellamokb, you always get the control that raised the event by the sender argument, you only need to direct it accordingly.
DropDownList ddl = (DropDownList)sender;
If you also need to get a link to the GridViewRow
DropDownList
(or any other control on the TemplateField GridView), you can use the NamingContainer
.
GridViewRow row = (GridViewRow)ddl.NamingContainer;
but I need to get the row index to get the value from the template field, which is not a combo box is a text field
You can get any control if you have a GridViewRow
link using row.FindControl("ID")
(TemplateField) or row.Cells[index].Controls[0]
(BoundField).
For example (suppose a TextBox
in another column):
TextBox txtName = (TextBox)row.FindControl("TxtName");
source share