onclick event in a gridview

C

cgian31

I have inserted a button in a gridview, via a template column.
Using the OnClick event I want to execute some other function, but I
need to get the row for which the button was pressed.
Unfortunately the datakey field, which is what I would need, is hidden,
therefore I cannot use the following code:

GridViewRow grdRow = (GridViewRow)Button1.Parent.Parent;
string key=grdRow.Cells[0].Text;

Any ideas?
 
C

cgian31

I have just solved it with:

int pos = grdRow.RowIndex;
DataKey keys = GridView1.DataKeys[pos];
 

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