Webforms Datagrid Sorting/Paging...

Discussion in 'ASP .Net' started by =?Utf-8?B?c2FsZWVr?=, May 23, 2005.

  1. Hi,

    I am trying to figure out why my datagrid has stopped firing the page and
    sort commands.

    Scenario:

    I originally had template columns in my datagrid and had set up custom
    bi-directional sorting as well as paging of the datagrid records.

    It worked fine. Then I decided to be clever on an update and thought I'd
    create the template columns programmatically - which I have done.

    Problem is, the paging command and sort commands have stopped firing.

    Please could someone give me advice on how to solve the problem.

    Here is my set up:

    Datagrid properties:

    OnSortCommand="DataGrid1_Sort"
    OnPageIndexChanged="DataGrid1_Page"

    Sort Command:

    Sub DataGrid1_Sort(ByVal sender As Object, ByVal e As
    DataGridSortCommandEventArgs) Handles DataGrid1.SortCommand
    ' Check to see if the column we clicked on is the current column
    defined
    ' in the sortCriteria property.
    If Me.sortCriteria = e.SortExpression Then
    If Me.sortDir = "desc" Then
    Me.sortDir = "asc"
    Else
    Me.sortDir = "desc"
    End If
    End If
    ' Assign the column clicked to the sortCriteria property
    Me.sortCriteria = e.SortExpression
    ' Now call the procedure to re-display the Data Grid
    DisplayGrid()
    End Sub


    Page COmmand:

    Sub DataGrid1_Page(ByVal sender As Object, ByVal e As
    DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
    DataGrid1.CurrentPageIndex = e.NewPageIndex
    DisplayGrid()
    End Sub

    Example of template column:

    Dim tDate As BoundColumn = New BoundColumn
    With tDate
    .HeaderText = "Date of B'Cast"
    .DataField = "Coverage_Date"
    .SortExpression = "Coverage_Date"
    .DataFormatString = "{0:d}"
    .HeaderStyle.Width = Unit.Point(60)
    .HeaderStyle.VerticalAlign = VerticalAlign.Top
    End With
    DataGrid1.Columns.AddAt(ColIndex, tDate)

    thanks,

    KS
     
    =?Utf-8?B?c2FsZWVr?=, May 23, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?c2FsZWVr?=

    Brock Allen Guest

    Two things might be the cause:

    1) The designer has somehow removed the event handles for the sorting and
    pagaing. This is a well known problem (at least in C#) and it happens sometimes.

    2) You're not recreating the DataGrid upon postback. Anything you do dynamically
    needs to be recreated upon every postback. I'd suggest doing this in CreateChildControls
    of the Page. The hard part is "remembering" across postbacks what you had
    added dynamically. Storing your own custom data in viewstate to remember
    this is a good approach.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Hi,
    >
    > I am trying to figure out why my datagrid has stopped firing the page
    > and sort commands.
    >
    > Scenario:
    >
    > I originally had template columns in my datagrid and had set up custom
    > bi-directional sorting as well as paging of the datagrid records.
    >
    > It worked fine. Then I decided to be clever on an update and thought
    > I'd create the template columns programmatically - which I have done.
    >
    > Problem is, the paging command and sort commands have stopped firing.
    >
    > Please could someone give me advice on how to solve the problem.
    >
    > Here is my set up:
    >
    > Datagrid properties:
    >
    > OnSortCommand="DataGrid1_Sort" OnPageIndexChanged="DataGrid1_Page"
    >
    > Sort Command:
    >
    > Sub DataGrid1_Sort(ByVal sender As Object, ByVal e As
    > DataGridSortCommandEventArgs) Handles DataGrid1.SortCommand
    > ' Check to see if the column we clicked on is the current
    > column
    > defined
    > ' in the sortCriteria property.
    > If Me.sortCriteria = e.SortExpression Then
    > If Me.sortDir = "desc" Then
    > Me.sortDir = "asc"
    > Else
    > Me.sortDir = "desc"
    > End If
    > End If
    > ' Assign the column clicked to the sortCriteria property
    > Me.sortCriteria = e.SortExpression
    > ' Now call the procedure to re-display the Data Grid
    > DisplayGrid()
    > End Sub
    > Page COmmand:
    >
    > Sub DataGrid1_Page(ByVal sender As Object, ByVal e As
    > DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
    > DataGrid1.CurrentPageIndex = e.NewPageIndex
    > DisplayGrid()
    > End Sub
    > Example of template column:
    >
    > Dim tDate As BoundColumn = New BoundColumn
    > With tDate
    > .HeaderText = "Date of B'Cast"
    > .DataField = "Coverage_Date"
    > .SortExpression = "Coverage_Date"
    > .DataFormatString = "{0:d}"
    > .HeaderStyle.Width = Unit.Point(60)
    > .HeaderStyle.VerticalAlign = VerticalAlign.Top
    > End With
    > DataGrid1.Columns.AddAt(ColIndex, tDate)
    > thanks,
    >
    > KS
    >
     
    Brock Allen, May 23, 2005
    #2
    1. Advertising

  3. Hi Allen, thx for your reply.

    The event handles are actually there in the code I posted.

    Also, the DisplayGrid() method does re-create the template columns.

    The problem is that at the moment is that the sort and paging events are not
    firing.

    regards,

    KS

    "Brock Allen" wrote:

    > Two things might be the cause:
    >
    > 1) The designer has somehow removed the event handles for the sorting and
    > pagaing. This is a well known problem (at least in C#) and it happens sometimes.
    >
    > 2) You're not recreating the DataGrid upon postback. Anything you do dynamically
    > needs to be recreated upon every postback. I'd suggest doing this in CreateChildControls
    > of the Page. The hard part is "remembering" across postbacks what you had
    > added dynamically. Storing your own custom data in viewstate to remember
    > this is a good approach.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > Hi,
    > >
    > > I am trying to figure out why my datagrid has stopped firing the page
    > > and sort commands.
    > >
    > > Scenario:
    > >
    > > I originally had template columns in my datagrid and had set up custom
    > > bi-directional sorting as well as paging of the datagrid records.
    > >
    > > It worked fine. Then I decided to be clever on an update and thought
    > > I'd create the template columns programmatically - which I have done.
    > >
    > > Problem is, the paging command and sort commands have stopped firing.
    > >
    > > Please could someone give me advice on how to solve the problem.
    > >
    > > Here is my set up:
    > >
    > > Datagrid properties:
    > >
    > > OnSortCommand="DataGrid1_Sort" OnPageIndexChanged="DataGrid1_Page"
    > >
    > > Sort Command:
    > >
    > > Sub DataGrid1_Sort(ByVal sender As Object, ByVal e As
    > > DataGridSortCommandEventArgs) Handles DataGrid1.SortCommand
    > > ' Check to see if the column we clicked on is the current
    > > column
    > > defined
    > > ' in the sortCriteria property.
    > > If Me.sortCriteria = e.SortExpression Then
    > > If Me.sortDir = "desc" Then
    > > Me.sortDir = "asc"
    > > Else
    > > Me.sortDir = "desc"
    > > End If
    > > End If
    > > ' Assign the column clicked to the sortCriteria property
    > > Me.sortCriteria = e.SortExpression
    > > ' Now call the procedure to re-display the Data Grid
    > > DisplayGrid()
    > > End Sub
    > > Page COmmand:
    > >
    > > Sub DataGrid1_Page(ByVal sender As Object, ByVal e As
    > > DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
    > > DataGrid1.CurrentPageIndex = e.NewPageIndex
    > > DisplayGrid()
    > > End Sub
    > > Example of template column:
    > >
    > > Dim tDate As BoundColumn = New BoundColumn
    > > With tDate
    > > .HeaderText = "Date of B'Cast"
    > > .DataField = "Coverage_Date"
    > > .SortExpression = "Coverage_Date"
    > > .DataFormatString = "{0:d}"
    > > .HeaderStyle.Width = Unit.Point(60)
    > > .HeaderStyle.VerticalAlign = VerticalAlign.Top
    > > End With
    > > DataGrid1.Columns.AddAt(ColIndex, tDate)
    > > thanks,
    > >
    > > KS
    > >

    >
    >
    >
    >
     
    =?Utf-8?B?c2FsZWVr?=, May 23, 2005
    #3
    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. Hajime Kusakabe

    DataGrid - sorting/paging problem

    Hajime Kusakabe, Jul 30, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    503
    Saravana
    Jul 31, 2003
  2. Mo
    Replies:
    1
    Views:
    4,242
    FFlannery
    Jan 30, 2004
  3. wh1974
    Replies:
    0
    Views:
    2,492
    wh1974
    Jan 12, 2005
  4. Red
    Replies:
    1
    Views:
    769
  5. Jimmy

    Sorting on *stacked* data using webforms datagrid

    Jimmy, Feb 26, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    127
    Jimmy
    Feb 26, 2005
Loading...

Share This Page