我正在尝试对数据进行分页。基本上我正在获取数据并希望在多页上显示它。但它不起作用。我正在使用 Asp.net 和 C# 进行编码。我正在使用 mysql 作为数据库。
代码如下: ASP代码
<asp:DataGrid runat="server" ID="RestData"
AllowPaging="True" PageSize="2"
OnPageIndexChanged="RestData_PageIndexChanged" AllowCustomPaging="True"
PagerStyle-Wrap="False">
<PagerStyle />
</asp:DataGrid>
C#代码:
protected void Page_Load(object sender, EventArgs e)
{
BindData();
}
public void BindData()
{
RestData.DataSource = call.GetReader(Convert.ToInt32(AreaData.SelectedValue));
//GetReader is function which returns the data reader of mysql
RestData.DataBind();
}
protected void RestData_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
RestData.CurrentPageIndex = e.NewPageIndex;
BindData();
}
输出:它显示两行(因为我给了pagesize 2)。但我看不到下一页。查询应该返回超过 2 行(当我使用中继器时确实会发生这种情况,但我无法在其中进行分页。
请提供一些解决方案(我无法用这个论坛中的任何其他解决方案解决我的问题,所以我创建了新的解决方案)
提前致谢。