Webforms Datagrid Sorting/Paging...

G

Guest

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
 
B

Brock Allen

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

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top