Re: Correct DataTable index from sorted DataView...

Discussion in 'ASP .Net' started by Nathan Baulch, Jun 26, 2003.

  1. > How do I get the correct DataTable index from a sorted DataView and a
    > DataGrid.SelectedIndex?
    >
    > I have a sortable DataGrid on a form with a ButtonColumn.
    > The DataGrid is bound to a DataView, which in turn is linked to a
    > DataTable. The DataView is persisted between round trips via a
    > session variable.
    >
    > When the ButtonColumn it is clicked, I wish to retrieve a value from
    > the corresponding row in the DataTable.
    > This works fine so long as the DataGrid has not been sorted.
    > When it is sorted, the value retrieved is from the incorrect row.


    My solution is to insert the primary key field as an invisible column into
    the DataGrid. When my button column is clicked, I use the code
    "e.Item.Cells[0].Text" to retrieve the selected primary key. I can then use
    that to lookup the whole row in the DataTable to get all associated
    information.

    It would be cleaner if DataView objects could translate indexes based on
    sorts and filters, but this will have to do.


    Nathan
     
    Nathan Baulch, Jun 26, 2003
    #1
    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. Ruslan

    DataTable and DataView

    Ruslan, Oct 29, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    14,067
  2. Andreas Klemt
    Replies:
    4
    Views:
    19,678
    nabeel
    Apr 19, 2012
  3. CodeMonkey
    Replies:
    1
    Views:
    740
    joyal jhaveri
    Feb 4, 2011
  4. JimLad
    Replies:
    0
    Views:
    387
    JimLad
    Jul 16, 2010
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    329
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page