问题:
当我尝试转到第2页或数据网格的任何其他后续页面时,它只会刷新页面。
标记:
<!--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>
代码背后:
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
现在,我甚至不确定为什么分页不起作用。我AllowPaging
等于true,我没有重新绑定PostBack上的数据,所以我很困惑。任何帮助都会很棒。感谢。
答案 0 :(得分:0)
您似乎没有将datagrid绑定到ObjectDataSource,EntityDataSource这样的控件,它会自动为您处理分页。
您需要从gridview处理Paging事件,然后自己重置页面索引
即。
gridview.PageIndex = e.newPageIndex
(我不在IDE机器上,因此无法确认这在语法上是否正确)