GridView RowCommand

M

Mike P

I have a ButtonField in my GridView with a CommandName, and I have a
method which I am using to capture each click of the button :

protected

void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{


if (e.CommandName == "OpportunityDetails")
{

...

}

}



My question is, how do I get hold of any of the values within the row
that I have clicked? I want to get at the ID field of the row that I
have clicked because I need to redirect to another page which will be a
DetailsView for this particular record.

Any help would be really appreciated.
 
N

Neutrino

The index of the row from were the command originated is in the
CommandArgument of the GridViewCommandEventArgs parameter of the event.


To get the GridViewRow do something like this (in C#):

GridViewRow row = GridView1.Rows(Convert.ToInt32(e.CommandArgument));

You may then use FindControl to get the controls within the row.

Hope this helps!
 
M

Mike P

Hi,

This doesn't work - I get the error 'Rows is a property but is used like
a method'.

Mike
 
Y

yossimotro

I think you shuold use [] instead of ().
anyway, where do you call this function from? I mean, what calls it?

Yossi.
 
Y

yossimotro

I understand that, what I don't understand is what action calls the
RowCommand...
I'm a newb to asp.net ;)

Yossi.
 

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