服务热线
153 8323 9821
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"