1,引用AspNetPager.dll
2,<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
.aspx页面使用:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="fenyeok.aspx.cs" Inherits="fenyeok" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>分页模板页,以后就用这个</title>
<style type="text/css">
a:Link{
font-size: 12px;
color: #3366cc;
text-decoration: none;
}
a:visited {
font-size: 12px;
color: #3366cc;
text-decoration: none;
}
.submitBtn {
background-image: url(submitfy.jpg);
font-size:12px;
height: 19px;
width: 37px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
}
</style>
</head>
<body style="font-size:12px;">
<form id="form1" runat="server">
<div>
分页模板页,以后就用这个,样式设置好
<br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Height="139px" Width="418px">
<Columns>
<asp:BoundField DataField="GoodID" HeaderText="GoodID" />
<asp:BoundField DataField="GoodName" HeaderText="GoodName" />
<asp:BoundField DataField="father" HeaderText="father" />
</Columns>
</asp:GridView> <br />
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" PageSize="5" HorizontalAlign="Center" OnPageChanged="AspNetPager1_PageChanged"
ShowCustomInfoSection="Left" Width="95%" meta:resourceKey="AspNetPager1" Style="font-size: 12px"
CustomInfoHTML="共<b><font color= red >%RecordCount%</font></b>条记录 当前页:<font color= red ><b>%CurrentPageIndex%/%PageCount%</b></font> 每页:%PageSize%"
AlwaysShow="True" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" SubmitButtonText="确定" SubmitButtonClass="submitBtn"
CustomInfoStyle="FONT-SIZE: 12px" InputBoxStyle="width:30px; border:1px solid #999999; text-align:center; " TextBeforeInputBox="转到第" TextAfterInputBox="页 " >
</webdiyer:AspNetPager>
</div>
</form>
</body>
</html>
.aspx.cs 代码:
using Maticsoft.DBUtility;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ListBind();
}
}
private void ListBind()
{
string sqlstr = "select * from testgood ";
DataSet ds = DbHelperSQL.Query(sqlstr);
this.AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;
//.net的自定义分页
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.PageSize = AspNetPager1.PageSize;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.DataSource = ds.Tables[0].DefaultView;
GridView1.DataSource = pds;
GridView1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
ListBind();
}
AspNetPager的属性设置:
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" Width="100%" NumericButtonCount="6" UrlPaging="true" 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>
<%--<webdiyer:AspNetPager ID="AspNetPager1" runat="server" PageSize="15" style="font-size:14px;" HorizontalAlign="Right" NumericButtonCount="6" NumericButtonTextFormatString="[{0}]" CustomInfoHTML="第 <font color= red ><b>%CurrentPageIndex%</b></font> 页 共 %PageCount% 页 显示 %StartRecordIndex%-%EndRecordIndex% 条" InputBoxStyle="width:24px; height:14px;" ShowInputBox="Always" SubmitButtonText=" GO " FirstPageText="[首 页]" PrevPageText="[上 页]" NextPageText="[下 页]" LastPageText="[末 页]" TextBeforeInputBox="转到第" TextAfterInputBox="页 " PagingButtonSpacing="10px" width="100%" ShowCustomInfoSection="Left" UrlPaging="true"></webdiyer:AspNetPager>
--%>
// NumericButtonCount="6" 显示页码的个数
// NumericButtonTextFormatString="[{0}]" 页码显示的格式
// ShowCustomInfoSection="left" 显示左边的(第几页、共几页、显示几条)
// TextBeforeInputBox="转到第" InputBox前面显示的字
// TextAfterInputBox="页" InputBox后面显示的字
// PagingButtonSpacing="10px" 字与字间的距离