Datagrid / Dataview won't sort

T

troyblakely

I am having trouble sorting a datagrid. I have read numerous posts on
this and other lists, and tried most of the suggestions, but none of
them have worked for me yet. I populate a dataset from two queries,
then I want to sort the data and bind it to a datagrid. Regardless of
what I have tried, the datagrid is populated with the unsorted data.
Any assistance you have would be appreciated.

I have attempted the sort using the dataview.sort method. See Below:

DataView view = this.dsInventory1.Tables["vInvLocDetail"].DefaultView;
view.Sort = "invTypeDesc ASC";
this.DataGrid1.DataSource = view;
this.DataGrid1.DataBind();


I have also attempted creating the dataview, specifying the sort for
the dataview, then parsing the results of the dataview into another
datatable and binding the datagrid to that datatable. See below:

DataView dv = new DataView(this.dsInventory1.vInvLocDetail, "",
"invTypeDesc", DataViewRowState.CurrentRows);
dv.Sort = "invTypeDesc";
DataTable dt = new DataTable();
foreach (DataRow row in dv.Table.Rows)
{
dt.ImportRow(row);
}
this.DataGrid1.DataSource = dt;
this.DataGrid1.DataBind();

Thank you for helping!
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top