如何在中继器中进行分页? [英] How to do paging in repeater?
本文介绍了如何在中继器中进行分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何对包含 10 条记录的表进行分页以一次仅显示其中的一部分.
后面的代码是:
How to do paging for a table of 10 records to show only some of them at once.
The code behind is:
protected void Page_Load(object sender, EventArgs e)
{
Rep_Bind();
}
private void Rep_Bind()
{
SqlDataAdapter adp = new SqlDataAdapter("select * from tbbook",ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
DataSet ds = new DataSet();
adp.Fill(ds);
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
这是html代码:
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<table>
<tr>
<td>
<img src='<%#Eval("bookimg") %>'height="50" width="50" />
<b>Title:</b><%#Eval("booktit" )%><br />
<b>Author:</b><%#Eval("bookauth") %><br />
<b>Publisher:</b><%#Eval("bookpub") %><br />
<b>Price:</b><%#Eval("bookprc") %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
现在我想要下一个和上一个的链接按钮.显示下一条和上一条记录.那么我应该怎么做?
Now i want linkbuttons for next and prev. which shows next and previous records.So what should i do for this?
推荐答案
您可以添加 DataPager 控件.
You could add a DataPager control.
虽然不确定您是否可以立即使用中继器进行寻呼.你需要做很多工作才能让它工作.检查此链接
Not sure you can get paging with a Repeater out of the box though. You'll require quite a bit of work to get it working. Check this link
您可能想改用 ListView.
You might want to use a ListView instead.
<asp:ListView ID="ListView1" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
<img src='<%#Eval("bookimg") %>' height="50" width="50" />
<b>Title:</b><%#Eval("booktit" )%><br />
<b>Author:</b><%#Eval("bookauth") %><br />
<b>Publisher:</b><%#Eval("bookpub") %><br />
<b>Price:</b><%#Eval("bookprc") %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:ListView>
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
这篇关于如何在中继器中进行分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文