ASP.NET 数据分页器
我正在尝试将 ASP.NET DataPager 控件链接到 ASP.NET ListView
<div>
<asp:ListView ID="ListView1" runat="server">
<ItemTemplate>
<a href="#"><%#DataBinder.Eval(Container.DataItem,"LinkText")%></a>
</ItemTemplate>
</asp:ListView>
<asp:DataPager runat="server" ID="DataPager1" PagedControlID="ListView1" PageSize="2">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</div>
在 Page_Load 中,我使用 DataTable 加载 ListView
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
_fl.ConnectToSQLServer();
DataTable dt = new DataTable();
dt.Load(_fl.GetCategories());
ListView1.DataSource = dt;
ListView1.DataBind();
_fl.DisconnectFromSQLServer();
}
}
数据显示正确,但 DataPager 无法正常工作
任何帮助将不胜感激。谢谢。
I am trying to link ASP.NET DataPager control to ASP.NET ListView
<div>
<asp:ListView ID="ListView1" runat="server">
<ItemTemplate>
<a href="#"><%#DataBinder.Eval(Container.DataItem,"LinkText")%></a>
</ItemTemplate>
</asp:ListView>
<asp:DataPager runat="server" ID="DataPager1" PagedControlID="ListView1" PageSize="2">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</div>
In Page_Load i load ListView with DataTable
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
_fl.ConnectToSQLServer();
DataTable dt = new DataTable();
dt.Load(_fl.GetCategories());
ListView1.DataSource = dt;
ListView1.DataBind();
_fl.DisconnectFromSQLServer();
}
}
Data is displayed correctly but DataPager does not work as it should
Any Help will be appreciated. Thank You.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 Page_Load 切换到 OnPreRender 以填充 ListView 并跳过 IsPostBack
检查
Switch from Page_Load to OnPreRender for populating the ListView and skip the IsPostBack check
Try