Get DataGrid Value

Discussion in 'ASP .Net Web Controls' started by Wayne Wengert, Feb 12, 2005.

  1. 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
    Wayne Wengert, Feb 12, 2005
    #1
    1. Advertising

  2. Wayne  Wengert

    Riki Guest

    Wayne Wengert wrote:
    > 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")

    --

    Riki
    Riki, Feb 13, 2005
    #2
    1. Advertising

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

    Wayne

    "Riki" <> wrote in message
    news:...
    > Wayne Wengert wrote:
    > > 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")
    >
    > --
    >
    > Riki
    >
    >
    Wayne Wengert, Feb 13, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. San Diego Guy
    Replies:
    0
    Views:
    542
    San Diego Guy
    Aug 7, 2003
  2. John Dalberg
    Replies:
    0
    Views:
    380
    John Dalberg
    Dec 20, 2005
  3. Rui Maciel
    Replies:
    2
    Views:
    3,020
    AndrewDover
    Dec 1, 2009
  4. John Dalberg

    How to get key value in a master datagrid from a detail datagrid?

    John Dalberg, Dec 20, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    132
    John Dalberg
    Dec 20, 2005
  5. Eskimo
    Replies:
    0
    Views:
    149
    Eskimo
    Feb 7, 2005
Loading...

Share This Page