How To Access Gridview row information inside RowCommand

In .net 1.1, the GridCommandEventArgs 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;

Reactions

Post a Comment

1 Comments

Please do not post any spam link in the comment box😊

Emoji
(y)
:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
x-)
(k)

Close Menu