Problem:
When I attempt to go to page 2 or any other subsequent page of the data grid, it does nothing but refresh the page.
Markup:
<!--Main DataGrid-->
<asp:DataGrid
ID="dgTasks"
runat="server"
PageSize="40"
AllowPaging="true"
AutoGenerateColumns="false"
ForeColor="#333333"
GridLines="Both"
Font-Size="Small"
AllowSorting="true"
OnItemDataBound="Item_DataBound" >
<HeaderStyle
BackColor="#990000"
Font-Bold="True"
ForeColor="White"
HorizontalAlign="Center"
Font-Size="Small"/>
<Columns>
...
</Columns>
<SelectedItemStyle
BackColor="#FFCC66"
Font-Bold="True"
ForeColor="Navy" />
<PagerStyle
BackColor="#CCCCCC"
ForeColor="#333333"
HorizontalAlign="Right"
Mode="NumericPages" />
<AlternatingItemStyle
BackColor="White" />
<ItemStyle
BackColor="#FFFBD6"
ForeColor="#333333" />
<FooterStyle
BackColor="#990000"
Font-Bold="True"
ForeColor="White" />
</asp:DataGrid>
Code Behind:
Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack Then
'DoNothing'
Else
BindData("")
End If
End Sub
Private Sub BindData(ByVal strDisplayCompleted As String, ByVal strSort As String)
Dim taskDataSet As TaskDataSet = New TaskDataSet()
Dim dt As DataTable = taskDataSet.GetData("N").Tables(0)
For Each dr As DataRow In dt.Rows
If dr.Item(2).ToString().StartsWith("Vacancy") Then
dr.Delete()
End If
Next
If strSort.Length > 0 Then
dt.DefaultView.Sort = strSort
End If
dgTasks.DataSource = dt.DefaultView
dgTasks.DataBind()
End Sub
Private Sub BindData(ByVal strSort As String)
BindData("N", strSort)
End Sub
Now, I’m not even close to sure why the pagination is not working. I have AllowPaging equal to true, I’m not re-binding the data on PostBack, so I’m confused. Any help would be great. Thanks.
It doesn’t appear you are binding the datagrid to a control like ObjectDataSource, EntityDataSource which would automatically take care of the paging for you.
You would need to handle Paging event from the gridview and then reset the page index yourself
i.e.
gridview.PageIndex = e.newPageIndex
(I am not at machine with IDE so cant confirm this is syntactically correct right now)