jamesdean666
asked on
C# Gridview Selected Row Index - Image Button OnClick Event
I am trying to return the selected row index (in C#) when clicking on a Gridview Template Field which is an ImageButton. I have added the template field below.. Any suggestions?
<asp:TemplateField ShowHeader="false">
<ItemTemplate>
<asp:ImageButton ID="btnRemoveMort" ToolTip="Remove Mortgagee from policy" runat="server" CausesValidation="false"
onclick="btnRemoveMort_Click" />
<cc1:ConfirmButtonExtender
ID="btnRemoveMort_ConfirmButtonExtender"
runat="server"
ConfirmText="Are you sure you want to Remove this Mortgagee from this Policy?"
Enabled="True"
TargetControlID="btnRemoveMort">
</cc1:ConfirmButtonExtender>
</ItemTemplate>
</asp:TemplateField>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was able to get it this way:
protected void btnRemoveMort_Click(object sender, EventArgs e)
{
try
{
ImageButton btnRemoveMort = sender as ImageButton;
GridViewRow row = (GridViewRow)btnRemoveMort .NamingCon tainer;
Int32 rowNum = row.RowIndex;
}
catch
{
}
}
protected void btnRemoveMort_Click(object
{
try
{
ImageButton btnRemoveMort = sender as ImageButton;
GridViewRow row = (GridViewRow)btnRemoveMort
Int32 rowNum = row.RowIndex;
}
catch
{
}
}
ASKER
Open in new window