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. Advertisements

  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. Advertisements

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,471
    Chris Taylor
    Oct 23, 2003
  2. DC Gringo

    Datagrid won't sort

    DC Gringo, Feb 29, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    1,463
    DC Gringo
    Mar 1, 2004
  3. CodeMonkey
    Replies:
    1
    Views:
    944
    joyal jhaveri
    Feb 4, 2011
  4. DC Gringo

    datagrid won't sort

    DC Gringo, Feb 29, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    257
    DC Gringo
    Mar 2, 2004
  5. 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:
    401
    Grant Harmeyer
    Jun 15, 2004
  6. bill

    my DataView won't sort

    bill, Oct 20, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    232
    Scott M.
    Oct 21, 2005
  7. PatLaf

    AspNet DataGrid won't fire sort routine

    PatLaf, Oct 29, 2003, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    374
    Alvin Bruney
    Oct 30, 2003
  8. Navin
    Replies:
    1
    Views:
    1,135
    Ken Schaefer
    Sep 9, 2003
Loading...