469,329 Members | 1,470 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,329 developers. It's quick & easy.

Datagrid / Dataview won't sort

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!

Nov 19 '05 #1
1 1590
Troy try looking at this at:-
http://www.dotnetjohn.com/articles.aspx?articleid=108
Hope that helps
Patrick

<tr*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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!

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Steve B. | last post: by
7 posts views Thread by DC Gringo | last post: by
1 post views Thread by Jeremy | last post: by
2 posts views Thread by ddaniel | last post: by
8 posts views Thread by Dennis | last post: by
9 posts views Thread by John Hernry | last post: by
4 posts views Thread by G .Net | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.