怎么在asp.net中的listView中使用DataPager来实现分页
<asp:ListView ID="lvBookList" runat="server"
ItemContainerID="layoutTableTemplate" DataKeyNames="Id"
onpagepropertieschanging="lvBookList_PagePropertiesChanging" >
<LayoutTemplate>
<div>
<ul>
<li></li>
</ul>
</thead>
<tbody>
<asp:PlaceHolder runat="server" ID="itemPlaceholder" />
</tbody>
</div>
</LayoutTemplate>
<ItemTemplate>
<ul>
<li><asp:Image ID="imgBook" Width="95px" Height="95px" ImageUrl='<%# Eval("ISBN","~/Images/book/{0}.jpg") %>' runat="server" /><br/>
<asp:HyperLink ID="HyperLink1" NavigateUrl="BookDetail.aspx" runat="server" Text='<%# SplidString.GetCut(Eval("Title"),10) %>' /><br/>
¥<asp:Label ID="Label1" Text='<%# Eval("UnitPrice") %>' runat="server" /></li> </ul>
</ItemTemplate>
</asp:ListView>
<div style=" text-align:center;">
<asp:DataPager ID="dpFenYe" runat="server" PagedControlID="lvBookList" PageSize="12">
<Fields><asp:NextPreviousPagerField ShowFirstPageButton="true" ShowLastPageButton="true" ShowNextPageButton="true" ShowPreviousPageButton="true"
FirstPageText="首 页" PreviousPageText="上一页" NextPageText="下一页" LastPageText="尾 页"/> </Fields></asp:DataPager>
<asp:TextBox ID="txtPage" runat="server" Width="25px"/> <asp:LinkButton Text="GO" runat="server" /></div> 展开
前台
<table class="usertableborder" cellspacing="1" cellpadding="3" width="96%" align="center" border="0">
<tr>
<td>
<span>共有<asp:Label runat ="server" ID ="lblTotal"></asp:Label>页,</span>
<span>每页<asp:Label runat ="server" ID ="lblEvery"></asp:Label>条</span>
<span>当前第<asp:Label runat ="server" ID ="lblPreSent"></asp:Label>页</span>
</td>
<td align="right"> <asp:LinkButton runat ="server" ID ="lbtnFirst" Text ="首页"
onclick="lbtnFirst_Click"></asp:LinkButton>
|<asp:LinkButton runat ="server" ID ="lbtnPre" Text ="上一页" onclick="lbtnPre_Click"></asp:LinkButton>
|<asp:LinkButton runat ="server" ID ="lbtnNext" Text ="下一页" onclick="lbtnNext_Click"></asp:LinkButton>
|<asp:LinkButton runat ="server" ID ="lbtnLast" Text ="尾页" onclick="lbtnLast_Click"></asp:LinkButton>
</td>
</tr>
</table>
后台:
int pageindex = 0;
protected void lbtnFirst_Click(object sender, EventArgs e)
{
pageindex = 0;
BindPage();
}
protected void lbtnPre_Click(object sender, EventArgs e)
{
if (int.Parse(lblPreSent.Text) - 1 == 0)
{
pageindex = 0;
BindPage();
}
else
{
pageindex = int.Parse(lblPreSent.Text) - 2;
BindPage();
}
}
protected void lbtnNext_Click(object sender, EventArgs e)
{
if (int.Parse(lblPreSent.Text) == int.Parse(lblTotal.Text))
{
pageindex = int.Parse(lblTotal.Text) - 1;
BindPage();
}
else
{
pageindex = int.Parse(lblPreSent.Text);
BindPage();
}
}
protected void lbtnLast_Click(object sender, EventArgs e)
{
pageindex = int.Parse(lblTotal.Text) - 1;
BindPage();
}
效果图:
你这个好像不是用DataPager这个控件来写的吧。这好像是那个分页类写的吧。我要的是要使用ListView来显示而用DatePager来实现分页啊
分页单独写 和listview的绑定关联起来不就行了吗?