.Net ramblings
# Tuesday, 20 December 2005
GridView - accessing row information inside RowCommand
in .net 1.1, the GridCommandEventArgs (or whatever) used to give access to the row that triggered the command. 
in .net 2.0, it isn't as obvious as that.  Fritz posted an excellent discussion on the matter, and i'm just posting his 2-line solution here for reference.

If your button is a ButtonField, then you can access the index of the item via e.CommandArgument.  This may be enough information to do whatever you need.

If your button is a LinkButton in a TemplateField, you have to add the CommandArgument as an attribute to the LinkButton:
CommandArgument='<%# Eval("id") %>'
Then in the code behind for RowCommand, you can use the following syntax:
string id = (string)e.CommandArgument;
thanks Fritz!

Tuesday, 20 December 2005 17:52:22 (GMT Standard Time, UTC+00:00)  #    Comments [0]  Asp.Net

OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview