日期:2014-05-17 浏览次数:20414 次
<body> <form id="form1" runat="server"> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <div><%#Eval("name")%></div> </ItemTemplate> </asp:Repeater> <webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="true" PageSize="1" CssClass="paginator" CurrentPageButtonClass="cpb" LastPageText="尾页" FirstPageText="首页" PrevPageText="上一页" NextPageText="下一页" UrlPaging="True" NumericButtonTextFormatString="{0}" ShowCustomInfoSection="Right" onpagechanged="AspNetPager1_PageChanged" CustomInfoTextAlign="Left" LayoutType="Div" > </webdiyer:AspNetPager> </form> </body>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data.SqlClient; using System.Data; using Wuqi.Webdiyer; namespace c_displays { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) Bind(); } public void Bind() { this.AspNetPager1.RecordCount = linksql.count("select * from good"); SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["AppServices"]); conn.Open(); SqlCommand cmd = new SqlCommand("select * from good order by id desc", conn); SqlDataAdapter sda = new SqlDataAdapter(); sda.SelectCommand = cmd; DataSet ds = new DataSet(); sda.Fill(ds, AspNetPager1.PageSize * (this.AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "temp"); DataTable dt = ds.Tables["temp"]; Repeater1.DataSource = dt; Repeater1.DataBind(); conn.Close(); } protected void AspNetPager1_PageChanged(object sender, EventArgs e) { Bind(); } } }