Results 1 to 2 of 2

Thread: grid sort

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2002
    Location
    London
    Posts
    678

    grid sort

    Hi,

    in my asp.net project, I am populating a datagrid ( on a web form ) using a datareader (GetAllTrades). See below...

    With dgNewTrades
    .DataSource = oCatTMS.GetAllTrades
    .DataKeyField = "tnum"
    .DataBind()
    End With

    The AllowSorting property is set to true.

    But I can not sort the data. When I place the mouse over the column names, I will not get the hyperlinks.

    Any thoughts?
    Thanks

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    There is quite a lot to do before sorting will work, as well as allowsorting=true you will need to set an on sort event such as

    OnSortCommand="sort_grid"
    Code:
        Sub Sort_Grid(ByVal sender As Object, ByVal e As DataGridSortCommandEventArgs)
    
            SortExpression = e.SortExpression.ToString()
            gridLeaderBoard.DataSource = createDataSource()
            gridLeaderBoard.DataBind()
    
        End Sub
    When you want to sort you have to resort the datasource and then rebind the grid to it's datasource. I do this by loading data from my database into a datatable, then creating a dataview (sorted by sortExpression).

    Hope this helps.

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