Find ItemIndex given DataKey in DataGrid

Discussion in 'ASP .Net' started by Rod, Mar 9, 2007.

  1. Rod

    Rod Guest

    While working with a datagrid I have a value for the datakey, from this I
    want to find the ItemIndex.

    How please?

    many thanks in advance.
     
    Rod, Mar 9, 2007
    #1
    1. Advertising

  2. On Mar 9, 12:59 pm, "Rod" <> wrote:
    > While working with a datagrid I have a value for the datakey, from this I
    > want to find the ItemIndex.
    >
    > How please?
    >
    > many thanks in advance.


    If I got you right, you can enumerate all items...

    VB:

    For Each dgItem In MyDataGrid.Items

    'Retrieve key value of each record based on DataGrids DataKeyField
    property
    If MyDataGrid.DataKeys(dgItem.ItemIndex) = datakey then

    .....
     
    Alexey Smirnov, Mar 9, 2007
    #2
    1. Advertising

  3. Rod

    Rod Guest

    "Alexey Smirnov" <> wrote in message
    news:...
    > On Mar 9, 12:59 pm, "Rod" <> wrote:
    >> While working with a datagrid I have a value for the datakey, from this I
    >> want to find the ItemIndex.
    >>
    >> How please?
    >>
    >> many thanks in advance.

    >
    > If I got you right, you can enumerate all items...
    >
    > VB:
    >
    > For Each dgItem In MyDataGrid.Items
    >
    > 'Retrieve key value of each record based on DataGrids DataKeyField
    > property
    > If MyDataGrid.DataKeys(dgItem.ItemIndex) = datakey then
    >



    That's good

    Thanks
     
    Rod, Mar 9, 2007
    #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. DataGrid change ItemIndex

    , Jan 5, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    495
    S. Justin Gengo
    Jan 6, 2006
  2. aleko
    Replies:
    2
    Views:
    8,314
    aleko
    Mar 22, 2008
  3. Alan Eilers

    ItemIndex is -1 in ItemCommand after selecting page in DataGrid

    Alan Eilers, May 12, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    255
    Scott Mitchell [MVP]
    May 13, 2004
  4. susie
    Replies:
    0
    Views:
    155
    susie
    Sep 29, 2003
  5. Jose Fernandez

    DATASET DATAGRID ITEMINDEX DATASETINDEX

    Jose Fernandez, May 25, 2005, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    289
    Jose Fernandez
    Jun 1, 2005
Loading...

Share This Page