C# - 杨涛分页控件AspNetPager sql分页篇
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# - 杨涛分页控件AspNetPager sql分页篇相关的知识,希望对你有一定的参考价值。
http://www.webdiyer.com/downloads/
前台
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <div> <table border=1> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <tr> <td><%#DataBinder.Eval(Container.DataItem,"id")%></td> <td><%#DataBinder.Eval(Container.DataItem,"year")%></td> <td><%#DataBinder.Eval(Container.DataItem,"month")%></td> <td><%#DataBinder.Eval(Container.DataItem,"day")%></td> </tr> </ItemTemplate> </asp:Repeater> </table> <webdiyer:AspNetPager ID="AspNetPager1" runat="server" Width="100%" NumericButtonCount="6" UrlPaging="false" NumericButtonTextFormatString="[{0}]" CustomInfoHTML="第 <font color=‘red‘><b>%CurrentPageIndex%</b></font> 页 共 %PageCount% 页 显示 %StartRecordIndex%-%EndRecordIndex% 条" ShowCustomInfoSection="left" FirstPageText="首页" LastPageText="末页" NextPageText="下页" PrevPageText="上页" Font-Names="Arial" BackColor="#F8B500" AlwaysShow="true" ShowInputBox="Always" SubmitButtonText="跳转" SubmitButtonStyle="botton" OnPageChanged="AspNetPager1_PageChanged" > </webdiyer:AspNetPager> </div> </form> </body> </html>
后台
using CY.CommonLibrary.Common; using System; using System.Collections.Generic; using System.Data; public partial class _Default : System.Web.UI.Page { private SQLDBHelper db = new SQLDBHelper(System.Configuration.ConfigurationManager.AppSettings["connstr"]); protected void Page_Load(object sender, EventArgs e) { if (!this.Page.IsPostBack) { BindGrid(); } } protected void AspNetPager1_PageChanged(object src, EventArgs e) { BindGrid(); } public void BindGrid() { int pageIndex = this.AspNetPager1.CurrentPageIndex - 1; int pageSize = this.AspNetPager1.PageSize = 20; string sql = @" declare @count int exec dbo.pagedemo 【pageIndex】,【pageSize】,@count output select @count "; sql = sql.FormatByKeywords ( new Dictionary<string, string>() { { "pageIndex", pageIndex.CheckData(CheckTypez.TransferSQL, "") }, { "pageSize", pageSize.CheckData(CheckTypez.TransferSQL, "") } }, "【", "】" ); DataSet ds = db.ExecuteDataSet(sql); this.AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[1].Rows[0][0].ToNotNullString()); Repeater1.DataSource = ds.Tables[0]; Repeater1.DataBind(); } }
以上是关于C# - 杨涛分页控件AspNetPager sql分页篇的主要内容,如果未能解决你的问题,请参考以下文章
asp.net 带有gridview的分页无刷新,急求,使用ajax
vs2005开发,用vs2010加载后提示 :创建控件时出错<asp:UpdatePanel>控件 未知的服务标记 AspNetPager