Get DataGrid Value

W

Wayne Wengert

I have a datagrid in my ASP.NET page that displays several rows based on
some user specified criteria. I have an Edit button and a Delete button in
each row. When the user clicks on either of those buttons I want to set a
Session variable to the contents of the field named "ID" in the selected row
and then call another page that will do the actual edit or delete. I have
the Private Sub DataGrid1_EditCommand(....) and it does seem to fire when I
click on the Edit button in any row but I get exceptions when I try to get
the value of the selected row?

I cannot figure out the syntax (VB) to get the value of the ID field in the
selected row.

Any help is appreciated

Wayne
 
R

Riki

Wayne said:
I have a datagrid in my ASP.NET page that displays several rows based
on some user specified criteria. I have an Edit button and a Delete
button in each row. When the user clicks on either of those buttons I
want to set a Session variable to the contents of the field named
"ID" in the selected row and then call another page that will do the
actual edit or delete. I have the Private Sub
DataGrid1_EditCommand(....) and it does seem to fire when I click on
the Edit button in any row but I get exceptions when I try to get the
value of the selected row?

I cannot figure out the syntax (VB) to get the value of the ID field
in the selected row.

You can use the DataKeys collection:
1) Set the Datagrid's DataKeyField property to "ID"
2) Use this expression in EditCommand:
Session("ID") = DataGrid1.DataKeys(e.Item.ItemIndex)

Without DataKeys, the expression would be something like:
e.Item.DataItem("ID")
or
DataBinder.Eval(e.Item.DataItem,"ID")
 
W

Wayne Wengert

Thanks. Let me go back and see if I can apply those changes and get things
working.

Wayne
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top