我做了一个ListView
来展示产品&它工作正常,但当我使用DataPager限制该页面中的产品数量时,这里出现了一些问题
代码是:
.cs
public void BindListView_Products()
{
int cate_id = int.Parse(Request.QueryString["cate_id"].ToString());
DataTable dt = new BALCate().GetProductsAllSubCate(cate_id);
ListView_Products.DataSource = dt;
ListView_Products.DataBind();
}
public void ddlNumber_SelectedIndexChanged(object sender, EventArgs e)
{
listview_pager.PageSize = Convert.ToInt32(ddlNumber.SelectedValue);
BindListView_Products();
}
的.aspx
<asp:UpdatePanel ID="up1" runat="server"><ContentTemplate>
//////some code
<div class="limit">
<b>Show:</b>
<asp:DropDownList ID="ddlNumber" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlNumber_SelectedIndexChanged">
<asp:ListItem Selected="True" value="5">5</asp:ListItem>
<asp:ListItem value="10">10</asp:ListItem>
<asp:ListItem value="15">15</asp:ListItem>
<asp:ListItem value="20">20</asp:ListItem>
<asp:ListItem value="25">25</asp:ListItem>
</asp:DropDownList>
</div>
<asp:ListView ID="ListView_Products" ItemPlaceholderID="itemplaceholder1" runat="server">
<LayoutTemplate>
<asp:PlaceHolder ID="itemplaceholder1" runat="server">
</asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<div>
<div class="left">
<div class="image">
<a href='ProductDetails.aspx?pid=<%#Eval("pid")%>'>
<img alt="Apple Cinema 30"" title="Apple Cinema 30""
src="<%#"Images/" + Eval("pimg_mid1") %>"></a></div>
<div class="name">
<a href="javascript:;"><%#Eval("pname")%></a>
<p><%#Eval("pdesc")%></p>
</div>
</div>
<div class="right">
<div class="price">$<%#Eval("pcost")%></div>
<div class="cart">
<a class="button" onclick="addToCart();">
<span>Add to Cart</span></a></div>
<div class="wish-list">
<a onclick="addToWishList();">Add to Wish List</a><br>
<a onclick="addToCompare();">Add to Compare</a></div>
</div>
<p class="clear">
</p>
</div>
</ItemTemplate>
</asp:ListView>
<div class="pagination">
<div class="results" style="float: right;">
<asp:DataPager PageSize="5" ID="listview_pager" PagedControlID="ListView_Products" runat="server">
<Fields><asp:NumericPagerField /></Fields>
</asp:DataPager>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
答案 0 :(得分:0)
http://www.codeproject.com/Articles/28419/A-Basic-ASP-NET-Pager-Control 一个没有太多编码的好数据管理器.. 我有同样的问题,但使用gridview。它也适用于listview .. :))