Results 1 to 8 of 8

Thread: Sort DataGrid

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Posts
    1,005

    Question Sort DataGrid

    I am having trouble sorting a datagrid. I am also trying to get answers on ASP.NET web site... http://forums.asp.net/1085845/ShowPost.aspx

    But I am not getting any help.

    If you check that post, you will see a link where you can see my web app and also download the solution.

    When I click a header text to sort, the grid empties all it's data leaving just the grid. NOTE: I also am using paging.

    Anyone help?

    Thanks

  2. #2
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    Re: Sort DataGrid

    Are you rebinding the grid after you have sorted the data in code?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Posts
    1,005

    Re: Sort DataGrid

    You can view my web app at...
    http://www.ourwebzone.com/codebase/index.aspx

    You can download the entire VS 2003 .NET solution here...
    http://www.ourwebzone.com/owzdepot/codebase.zip

    Take a look and see what you can find.

    Thanks
    .

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Posts
    1,005

    Re: Sort DataGrid

    Quote Originally Posted by Patch21
    Are you rebinding the grid after you have sorted the data in code?
    Yes... I am binding afterwards.

  5. #5
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    Re: Sort DataGrid

    All I can think of is that your dataview on postback is empty, as you fill it in your InitializeComponent method. Is the dataview empty on postback? If so, you need to get the data on each postback.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Posts
    1,005

    Re: Sort DataGrid

    Do you download and look at my solution?

    This is what I have...

    VB Code:
    1. Private Sub DataBind1()
    2.         OleDbDataAdapter1.Fill(DataSet11)
    3.         DataGrid1.DataBind()
    4.     End Sub
    5.  
    6.     Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, _
    7. ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)_
    8. Handles DataGrid1.PageIndexChanged
    9.         DataGrid1.CurrentPageIndex = e.NewPageIndex
    10.         DataBind1()
    11.     End Sub
    12.  
    13.     Private Sub DataGrid1_SortCommand(ByVal source As Object, _
    14. ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) _
    15. Handles DataGrid1.SortCommand
    16.         DataView1.Sort = e.SortExpression + " ASC"
    17.         DataGrid1.DataSource = DataView1
    18.         DataBind1()
    19.     End Sub

    I didn't notice, but I had DatGrid1.Databind(), which is wrong. It should of been just DataBind()... that is where my data is bound to grid.

    So, now the data stays bound to grid, but doesn't sort.

    See at.. http://www.ourwebzone.com/codebase/index.aspx

    Thanks
    Last edited by epixelman; Oct 26th, 2005 at 06:07 AM.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Posts
    1,005

    Re: Sort DataGrid



    .

  8. #8
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    Re: Sort DataGrid

    Not too sure, maybe its because you set the datasource of the datagrid in your html? Take that out and see what happens.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width