我正在尝试向我的Gridview添加分页。我在属性中添加了以下内容:
<table id="myTable" class="table tbody" runat="server" visible="false">
<tbody>
<tr>
<td>
<asp:DataGrid ID="myGrid" runat="server" CssClass="table table-striped tbody" Visible="false"
AutoGenerateColumns="True"
AllowPaging="True"
AllowCustomPaging="true"
ForeColor="black"
HeaderStyle-Font-Bold="true"
HeaderStyle-ForeColor="black"
GridLines="None"
EnableViewState="false" />
</td>
</tr>
</tbody>
</table>
结果集返回22行,并且在第一页上正确显示了前10条,但是我没有任何选择可以移动到下一页。没有数字或箭头可按以移至第2页,依此类推。
谁能帮我解决我做错的事情?
我认为您应该删除Allow Custom paging property
并根据需要设置PageSize
属性。然后,您必须将OnPageIndexChanging
事件添加到网格中。因此,例如:
AllowPaging="true" PageSize="8" OnPageIndexChanging="stockTakeGrid_PageIndexChanging"
因此,在后面的代码中,您还必须处理上述事件,例如:
protected void stockTakeGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
stockTakeGrid.DataSource = ViewState["stockDetails"];
stockTakeGrid.PageIndex = e.NewPageIndex;
stockTakeGrid.AutoGenerateColumns = false;
stockTakeGrid.DataBind();
}
最初加载网格时,将页面索引设置为0
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句