Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: Correct DataTable index from sorted DataView...

Reply
Thread Tools

Re: Correct DataTable index from sorted DataView...

 
 
Nathan Baulch
Guest
Posts: n/a
 
      06-26-2003
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting index-15, index-9, index-110 "the human way"? Tomasz Chmielewski Perl Misc 4 03-04-2008 05:01 PM
Sort a datatable and create a new datatable Fredrik Rodin ASP .Net 3 09-28-2007 07:28 AM
how to return index of sorted vector boheman@gmail.com C++ 4 12-14-2006 05:14 PM
sorting list and then return the index of the sorted item custard_pie Python 10 05-03-2005 07:41 PM
Adding DataTable Rows To another DataTable J. Babe ASP .Net 1 08-15-2003 05:04 PM



Advertisments