Thursday, March 29, 2012

Paging problem

I've created a Datagrid and the AllowPaging is set to True, PageSize is set to 3. My database have a total of 7 records. When I run my page, only 3 records are display due to the PageSize, as I have 7 records, it shows there are total 3 pages. When I click the 2 or 3, nothing happen and it is still on the first page as it should display the next page with another 3 records. Any idea on fixing this problem.

I'm using Webmatrix 1.1 and MS SQL server 2000.

Thanks in advance.If you're using the default code generated by the Web Matrix it should just work. A few things to check:
1. Are you using a dataset which is bound to the datagrid containing the data which should be displayed? The default paging mechanism only works fine with a dataset using the Web Matrix code.
2. Is there a DataGrid_Page event handler in your code? It should contain:


DataGrid1.CurrentPageIndex = e.NewPageIndex
BindGrid()

Check if the event is registered correctly to the PageIndexChanged event of the datagrid. It should point to the DataGrid_Page event method.
3. The Page_Load event should check for a postback of the page and only bind the data to the grid when there's NO postback:

Sub Page_Load(Sender As Object, E As EventArgs)
If Not Page.IsPostBack Then
' Databind the data grid on the first request only
' (on postback, rebind only in paging command)
BindGrid()
End If
End Sub

Hope this can help you?

Tip: turn page tracing on (Trace = "True") to monitor which events are fired to determine where the problem is located in the code.
Thanks bdesmet, I've got it running now.

0 comments:

Post a Comment