DataView.sort issue

D

David

Thought I would try one last time; if you can help,
thanks. I am trying to sort a datatable, and return the
sorted results. Not working with a datagrid, or ASP.NET.
Cannot do the sort on the database.

DataView dv = existing table view
dv.sort = "EVENT_DATE DESC"

DataTable NewTable = new DataTable();
foreach (DataRowView drv in dv)
{
DataRow Row = drv.Row;
NewTable.ImportRow(Row);
}
return NewTable

If I peek at the values of the rows during the loop
through dv, they are what I would expect after a sort.
However the end result looks the same as the existing un-
sorted table . What am I missing here?

Thanks,

David
 
W

William Ryan

David:

If you iterate through the new datatable and the results are what you want
them to be, then the 'problem' is in your binding. As I mentioned before
(Ignore the grid and ASP.NET for a second), you don't need to pass in a
dataview to a function with a DataTable and return the datatable, just to
have a sorted DataTable. If you aren't binding to a grid or any other
control, then as you state, when you iterate through the view, it's sorted
correctly. So you can bypass your function and just use those results
locally. If it's a binding issue, then that's probably where the problem
exists. You can do just about anything with a DataView that you can with a
Table..so there probably isn't a good reason to pass a DataView into
something sort it there, and as you walk through it, creatre a DataTable and
return the table. THen, you'd at a minimum have two identical tables and a
dataview when all you needed was a table and dataview
 
G

Guest

My understanding is that when a sort is done, the dataview
is affected, but not the underlying table, and that if I
need to return the results in the sorted order (and don't
have anything to bind to), I need to iterate through the
dataview and create a table with the new results.

I wish I could just bind to a datagrid, but because I am
using a ADO.NET data tier component with an ASP website, I
don't have anything I can bind to (am I wrong about this?)
BTW, in case you are wondering, I convert the sorted
dataset into ADO XML, and return the file to be used by
the ASP website.

Thanks,

David
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top