What to use instead of the CommandArgument in DataGrids?

G

Guest

In the datagrid ButtonColumn, for both the pressButton and linkButton, there
is no CommandArgument property. My question is:

How do i go about programming events using the commandName without knowing
the value associated with the row? Is there a different property or a hack i
can use?

Thanks,
 
A

Andy Fish

as long as you don't need a different property for each column, use the
DataKeyField property on the grid.

e.g. if you set DataKeyField="ISBN" you can retrieve the ISBN inside an
event using

(string)(myGrid.DataKeys[e.Item.ItemIndex])

Andy
 
B

Brock Allen

And the suggestion Andy makes should be done inside your DataGrid's ItemCommand
event. This is fired when a Button with a CommandName is clicked. The DataGridItemCommandEventArgs
(which is the e.Item.Itemindex Andy speaks of) is the parameter to the ItemCommand
event.




as long as you don't need a different property for each column, use
the DataKeyField property on the grid.

e.g. if you set DataKeyField="ISBN" you can retrieve the ISBN inside
an event using

(string)(myGrid.DataKeys[e.Item.ItemIndex])

Andy

In the datagrid ButtonColumn, for both the pressButton and
linkButton,
there
is no CommandArgument property. My question is:
How do i go about programming events using the commandName without
knowing
the value associated with the row? Is there a different property or a
hack
i
can use?
Thanks,
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top