By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,157 Members | 891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,157 IT Pros & Developers. It's quick & easy.

Datagrid / Dataview won't sort

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.