Datagrid button

F

Freddy

I have a datagrid that I created and fill a dataset using a stored proc.
and bind it. The first column( a linkbutton button column) in the DG
contains a number, the second a name. When the user presses the button I
need the number displayed on the link. The number is a field from the
database. I got the code to trap the button press to work, but I cant get
the number displayed.. (vb.net)

Sub Gridclick( byval sender as object, byval e as datagridcommandeventargs)
handles datagrid1.ItemCommand

I've tried different variations of casting such as
CType(e.Item.Cells(0).Controls(0), ButtonColumn) or LinkButton and other
variations
I also tried to use the e.item.cell(0).text and other variations of the
e.item....
I CAN READ the NAME part of the row with e.item.cells(1).text.
WHAT GIVES..?
I tried many different commands till I am frustrated.
A code sample to read the first col link would be great.
Thank You
F
 
A

Andrew Backer

1) have you
Have you tried looking at the keys collection (since I assume that is
what you want)?
int id = (int)dgrid.DataKeys[ e.Item.ItemIndex ];
It requires that you have your datakey field set though (DataKeyField=
"MyId")

If, however, you are just looking to get whatever text is there, i'm
not sure I can help you. I think the buttoncolumn is just meant to
post back a command ( CommandName="blah" ) and a row #, so you can do
something with it.

Yes, the datagrid is the most annoying half assed thing out there, but
it sorta works if you go crazy enough.

- Andrew
 

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,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top