Datagrid / Dataview won't sort

Discussion in 'ASP .Net' started by troyblakely@gmail.com, Nov 5, 2005.

  1. Guest

    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 5, 2005
    #1
    1. Advertising

  2. Troy try looking at this at:-
    http://www.dotnetjohn.com/articles.aspx?articleid=108
    Hope that helps
    Patrick

    <> wrote in message
    news:...
    > 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!
    >
     
    Patrick.O.Ige, Nov 5, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Denzil

    Query on DataView.Sort Property

    Denzil, Oct 21, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,274
    Chris Taylor
    Oct 23, 2003
  2. CodeMonkey
    Replies:
    1
    Views:
    740
    joyal jhaveri
    Feb 4, 2011
  3. Grant Harmeyer

    DataView.Sort causing duplicate entries in a DataGrid control

    Grant Harmeyer, Jun 15, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    192
    Grant Harmeyer
    Jun 15, 2004
  4. bill

    my DataView won't sort

    bill, Oct 20, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    163
    Scott M.
    Oct 21, 2005
  5. Navin
    Replies:
    1
    Views:
    730
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page