gridview row command

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I find out the row index selected in the gridveiw row command method?

I have an imageButton in a gridview cell and its corresponding code in the
row command method needs to know the row index in question in order to set
the background of the cell to a different color. But the selectedIndex value
doesnt return a value as expected.

Is there something I am missing?
 
You can use the SelectedDataKey property to retrieve the DataKey object for
the currently selected row. You can also use the SelectedValue property to
retrieve the data key value for the currently selected row directly.
 
not?
Search for the row with the same id and you'll know the row, right?
(row.FindControl("imagebutton") for the imagebutton or search for the cell
where the imagebutton is in.
 
The SelectedDataKey only holds the datakey of the datasource, this is not the
same as the row index, the datakey could be a customerID which is not going
to be the same as the row index. Or am I mistaken?
 
No you are right, sorry
What I always do is that I have a column (visible = false) with the unique
record ID.
With that I can find the row which was selected.
I was in the wrong assumpsion you did that also.
 

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

Back
Top