1.表示层,引用->添加引用->浏览->/bin/AspNetPager.dll确定
2.default.aspx
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<asp:Repeater id="myRepeater" runat="server"><ItemTemplate>
<tr><td><%#Eval("id")%></td><td><%#Eval("GuestName")%></td><td><%#Eval("GuestEmail")%></td><td><%#Eval("content")%></td></tr>
</ItemTemplate></asp:Repeater>
<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="#EDEDED" AlwaysShow="true" SubmitButtonText="跳转" SubmitButtonStyle="botton" OnPageChanging="AspNetPager1_PageChanging1" HorizontalAlign="Right" ></webdiyer:AspNetPager>
3.default.aspx.cs
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack){
bind();
}
}
private void bind()
{ /把记录总数赋值给分页控件
string sql = "select [id],[GuestName],[GuestEmail],[Content],[Time],[Reply] from [Tmessage] order by id desc";
DataSet ds = ACCHelper.ExecuteDataset(ACCHelper.ConnectionStringLocalTransaction, CommandType.Text, sql, null);
AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;
int pageSize = AspNetPager1.PageSize = 6;
int pageIndex =AspNetPager1.CurrentPageIndex - 1;
绑定当前页的数据到Repeater控件
DataSet dd = GVBind(sql,pageIndex,pageSize);
myRepeater.DataSource = dd;
myRepeater.DataBind();
}
//PageChanged事件处理
protected void AspNetPager1_PageChanging1(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{ AspNetPager1.CurrentPageIndex = e.NewPageIndex; bind(); }
//返回当前页dataset
public static DataSet GVBind(string sqlstring, int page_index, int page_size)
{
int firstPage = page_index * page_size;
OleDbConnection myCon = new OleDbConnection(ACCHelper.ConnectionStringLocalTransaction);
DataSet ds = new DataSet();
OleDbDataAdapter myConAdp = new OleDbDataAdapter(sqlstring, myCon);
myConAdp.Fill(ds, firstPage, page_size, "article");
myCon.Close();
return ds;
}
}