WebFormAspNetPager用法(转载)
1、增加用户控件的引用:
方法1:在<web>节点下添加上下列内容
<pages validateRequest="false">
<controls>
<add tagPrefix="webdiyer" namespace="Wuqi.Webdiyer" assembly="AspNetPager"/>
</controls>
</pages>
方法2:在前前台页面加入
<%@ Register TagPrefix ="webdiyer" Namespace ="Wuqi.Webdiyer" Assembly ="AspNetPager" %>
2、在页面上引用用户控件( 必须加入事件)
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" onpagechanged="AspNetPager1_PageChanged" >
</webdiyer:AspNetPager>
3、基本属性
AspNetPager1.RecordCount = 100;//记录总数
AspNetPager1.PageSize = 10;//每页显示的记录数
AspNetPager1.CurrentPageIndex = 5;//当前页索引
4、分页sql语句
SELECT TOP 页大小 * FROM 表 WHERE (ID NOT IN
(SELECT TOP 页大小*(要访问的页-1) id FROM 表 ORDER BY id))
ORDER BY ID
5、必须事件//点击分页按钮时激发
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
if (!IsPostBack)
{
AspNetPager1_PageChanged(new object(), new EventArgs());
}
//通用格式:
protected void AspNetPager1_PageChanged(object sender, EventArgs e)//点击分页按钮时激发
{
string tables = "";//要查询的数据表:table
string text = "";//要查询的字段:*
string cd = "";//sql查询的条件 :type='你好'
string px = "";//sql排序字段 :order by id
AspNetPager1.PageSize = 10;//设置每页显示的记录
AspNetPager1.RecordCount = sqldb.countRunProc("select count(id) from " + tables + " where (" + cd + ") ");//记录总数
string ye = (AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1)).ToString(); //要显示的页前面所有的记录
string fenye = "select top " + AspNetPager1.PageSize + " " + text + " from " + tables + " where (id not in (select top " + ye + " id from " + tables + " where (" + cd + ") " + px + ")) and (" + cd + ") " + px + "";
GridView1.DataSource = sqldb.dtRunProc(fenye);
GridView1.DataBind();
}