ASP.Net Datagrid sort

Discussion in 'ASP .Net Web Controls' started by George Zolla, Dec 6, 2003.

  1. George Zolla

    George Zolla Guest

    I can sort the contents of a datagrid using the following code but when I
    change to another page in the dataset I lose the sort. How do I sort the
    dataset and keep it when I go to a new page?

    Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
    DataGrid1.SortCommand

    Dim DataView1 As New DataView(DsTerritories1.Territories)

    DataView1.Sort = e.SortExpression

    DataGrid1.DataSource = DataView1 'need this to rebind grid

    DataGrid1.DataBind()

    End Sub

    Here is the paging code:

    Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
    DataGrid1.PageIndexChanged

    'need to rebind the datgrid to the source after the page is changed

    'However if a sort is performed before the page change the sort is lost

    'Need to have dataview with scope for entire project to correct this.

    DataGrid1.CurrentPageIndex = e.NewPageIndex

    DataGrid1.DataSource = DsTerritories1.Territories

    DataGrid1.DataBind()

    End Sub
     
    George Zolla, Dec 6, 2003
    #1
    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. =?Utf-8?B?c3Jpbmk=?=

    RE: ASP.Net DataGrid Sort event problems

    =?Utf-8?B?c3Jpbmk=?=, May 13, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    481
    =?Utf-8?B?c3Jpbmk=?=
    May 13, 2004
  2. =?Utf-8?B?c3Jpbmk=?=

    RE: ASP.Net DataGrid Sort event problems

    =?Utf-8?B?c3Jpbmk=?=, May 13, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    462
    =?Utf-8?B?c3Jpbmk=?=
    May 13, 2004
  3. avnrao
    Replies:
    0
    Views:
    556
    avnrao
    May 13, 2004
  4. =?Utf-8?B?dHNhcm5h?=

    RE: ASP.Net DataGrid Sort event problems

    =?Utf-8?B?dHNhcm5h?=, Jun 18, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,564
    =?Utf-8?B?dHNhcm5h?=
    Jun 18, 2004
  5. Navin
    Replies:
    1
    Views:
    770
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page