ASP.NET 2.0 equivalent for e.Item.ItemIndex ?

Discussion in 'ASP .Net Web Controls' started by RG, Mar 27, 2006.

  1. RG

    RG Guest

    Hello,

    I'm raising an event in a datagrid when clicking on a deletecommand button.
    I want to get the selected value of the datagrid.

    In ASP.NET 1.1 I did this whit e.Item.ItemIndex
    In ASP.NET 2.0 I can't use this anymore because EventArgs e has only the
    properties/methods tostring, Equals, getHashcode and getType.

    Does somebody know a solution for this ?

    thx,
     
    RG, Mar 27, 2006
    #1
    1. Advertising

  2. Use the ItemCommand event:

    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.itemcommand(VS.80).aspx

    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "RG" wrote:

    > Hello,
    >
    > I'm raising an event in a datagrid when clicking on a deletecommand button.
    > I want to get the selected value of the datagrid.
    >
    > In ASP.NET 1.1 I did this whit e.Item.ItemIndex
    > In ASP.NET 2.0 I can't use this anymore because EventArgs e has only the
    > properties/methods tostring, Equals, getHashcode and getType.
    >
    > Does somebody know a solution for this ?
    >
    > thx,
    >
    >
    >
     
    Phillip Williams, Mar 27, 2006
    #2
    1. Advertising

  3. RG

    Guest

    It should work just the way you're familiar with because
    DataGridCommandEventArgs still has the Item property.

    Protected Sub dataGrid1_DeleteCommand(ByVal source As Object, ByVal e
    As DataGridCommandEventArgs) Handles dataGrid1.DeleteCommand

    lbl.Text = "Deleting row number " & e.Item.ItemIndex
    myDataView.Delete(e.Item.ItemIndex)
    dataGrid1.DataBind

    End Sub
     
    , Mar 27, 2006
    #3
  4. RG

    RG Guest

    <> schreef in bericht
    news:...
    > It should work just the way you're familiar with because
    > DataGridCommandEventArgs still has the Item property.
    >
    > Protected Sub dataGrid1_DeleteCommand(ByVal source As Object, ByVal e
    > As DataGridCommandEventArgs) Handles dataGrid1.DeleteCommand
    >
    > lbl.Text = "Deleting row number " & e.Item.ItemIndex
    > myDataView.Delete(e.Item.ItemIndex)
    > dataGrid1.DataBind
    >
    > End Sub



    Hi, this works but e.Item.ItemIndex returns the number of the row in the
    datagrid, but not the datakeyfield.
    How can i see this ?

    thx
     
    RG, Mar 28, 2006
    #4
  5. RG

    Guest

    Are you asking how to get the primary key value for the row in
    question? If you are then use the DataKeys collection property of your
    DataGrid.

    'Within the DeleteCommand (or ItemCommand event handler and filtering
    for the delete command)
    datagrid1.DataKeys(e.Item.ItemIndex)
     
    , Mar 28, 2006
    #5
  6. RG

    RG Guest

    <> schreef in bericht
    news:...
    > Are you asking how to get the primary key value for the row in
    > question? If you are then use the DataKeys collection property of your
    > DataGrid.
    >
    > 'Within the DeleteCommand (or ItemCommand event handler and filtering
    > for the delete command)
    > datagrid1.DataKeys(e.Item.ItemIndex)


    thats it yes!

    Thanks for the solution
     
    RG, Mar 29, 2006
    #6
    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. Stephan

    e.Item.ItemIndex returns wrong value

    Stephan, Jul 26, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    3,497
    Stephan Bussing
    Jul 26, 2004
  2. brian yeo via .NET 247

    read row (1 field) from ItemIndex

    brian yeo via .NET 247, Mar 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    731
    brian yeo via .NET 247
    Mar 7, 2005
  3. Fred Dag
    Replies:
    1
    Views:
    2,051
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=
    Jan 20, 2006
  4. Joel Finkel

    DataGrid1.DataKeys[e.Item.ItemIndex] array index out of bounds

    Joel Finkel, Sep 4, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    362
    Joel Finkel
    Sep 4, 2003
  5. Scott M.

    e.Item.ItemIndex and e.Item.DataSetIndex

    Scott M., Nov 1, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    7
    Views:
    284
    Steven Cheng[MSFT]
    Apr 13, 2005
Loading...

Share This Page