Getting the index of image click event in a datagrid

  • Thread starter Brett Wesoloski
  • Start date
B

Brett Wesoloski

I am having problems getting the index of an image click event in a
datagrid. Every time I look at the index it is -1.

What I am trying to do is get the index of the row in which the imagebutton
was clicked. So that I can then go and look into a hidden field as to what
the value will be that I need to use.

I am using a template column to create the imagebutton.

<asp:TemplateColumn HeaderText="">
<ItemTemplate>
<asp:ImageButton ID="btnF" Runat="server"
ImageUrl="/common/images/F.gif"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>

Here is my C# code

public void btnF_Click(object sender, ImageClickEventArgs e)
{
dgInvestmentInfo.SelectedIndex always returns -1 no matter what row I click
on...
}

Well not sure what I am doing wrong but I can't seem to figure out how to
get the row of the datagrid that was clicked.

I am binding a datatable to the datagrid.

Well hopefully someone can help me with this.

Thanks,
Brett
 
B

Brett Wesoloski

Ok I figured out what I was doing wrong.

Needed to do this in the click event.

ImageButton imageButtonF = (ImageButton)sender;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top