Retreiving a DataItem in the GridView's RowCommand

N

Nathan Sokalski

I have a GridView with a ButtonField. In the RowCommand I need to use the
value of one of the fields used in that row. I am having trouble doing this,
so I would appreciate it if someone could help me here. Thanks.
 
N

Nathan Sokalski

This is a ButtonField, and the reason I need the value is so that I know
what SQL statement to execute on the database. The value is not being used
for display, it is being used for functionality. The RowDataBound event will
not help me here because I need to use the value in the RowCommand event, so
I need a way to access the data from the current row.
 
P

Phil H

This is a ButtonField, and the reason I need the value is so that I know
what SQL statement to execute on the database. The value is not being used
for display, it is being used for functionality. The RowDataBound event will
not help me here because I need to use the value in the RowCommand event, so
I need a way to access the data from the current row.









- Show quoted text -

Hi

There a various ways of doing this but if you require the primary key
then use the DataKeys property of the GridView control. Also make sure
that DataKeyNames is set correctly (it's available in the designer).

Other than that the Button control could have its CommandArgument
property bound to the required column name. Set the CommandName
property of the button control to something distinctive and then
process the click event in the GridViews RowCommand where the "e"
parameter will have those same properties set accordingly - you can
then detect it by checking the e.CommandName property and then
e.CommandArgument will then return the required value of the field.

HTH
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top