这是修改的一个1.1的一个REpeater的分页程序,现在改成2.0的了,可以通用了,呵呵,小弟技术烂,有大虾的请指教啊
前台是
<% @ Control Language = " C# " AutoEventWireup = " true " CodeFile = " Page.ascx.cs " Inherits = " Page " %> < table width = " 100% " border = " 0 " cellpadding = " 2 " cellspacing = " 1 " bgcolor = " #CCCCCC " > < tr valign = " middle " bgcolor = " #FFFFFF " > < td height = " 25 " > 共 < asp:Literal ID = " RecordCount " runat = " server " ></ asp:Literal > 条记录 & nbsp; </ td > < td > 共有 < asp:Literal ID = " PageCount " runat = " server " ></ asp:Literal > 页 </ td > < td > 当前第 < asp:Literal ID = " Pageindex " runat = " server " ></ asp:Literal > 页 </ td > < td > < asp:HyperLink ID = " FirstPage " runat = " server " Text = " 首页 " ></ asp:HyperLink > < asp:HyperLink ID = " PrevPage " runat = " server " Text = " 上一页 " ></ asp:HyperLink > < asp:HyperLink ID = " NextPage " runat = " server " Text = " 下一页 " ></ asp:HyperLink > < asp:HyperLink ID = " LastPaeg " runat = " server " Text = " 尾页 " ></ asp:HyperLink ></ td > < td > 跳转到 < asp:Literal ID = " Literal1 " runat = " server " ></ asp:Literal > 页 </ td > </ tr > </ table >using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text; using System.Data.OleDb; public partial class Page : System.Web.UI.UserControl ... { private void Page_Load(object sender, System.EventArgs e) ...{ //这个是不能少的,不然ASPX页面就不能用这控件里的函数了 } public void Initialize(string ConnectionString, Repeater DataPanl, string SelectCommand, string PageUrl) ...{ OleDbConnection conn = new OleDbConnection(ConnectionString); conn.Open(); OleDbDataAdapter oda = new OleDbDataAdapter(SelectCommand, conn); DataSet ds = new DataSet(); oda.Fill(ds); conn.Close(); try ...{ PagedDataSource pds = new PagedDataSource(); pds.DataSource = ds.Tables[0].DefaultView; pds.AllowPaging = true; pds.PageSize = 5; int CurPage; if (Request.QueryString["Page"] != null) ...{ CurPage = Convert.ToInt32(Request.QueryString["page"]); } else ...{ CurPage = 1; } pds.CurrentPageIndex = CurPage - 1; DataPanl.DataSource = pds; DataPanl.DataBind(); RecordCount.Text = pds.DataSourceCount.ToString(); PageCount.Text = pds.PageCount.ToString(); Pageindex.Text = CurPage.ToString(); Literal1.Text = PageList(pds.PageCount, CurPage, PageUrl); FirstPage.NavigateUrl = PageUrl + "page=1"; PrevPage.NavigateUrl = PageUrl + "page=" + (CurPage - 1); NextPage.NavigateUrl = PageUrl + "page=" + (CurPage + 1); LastPaeg.NavigateUrl = PageUrl + "page=" + pds.PageCount.ToString(); if (CurPage <= 1 && pds.PageCount <= 1) ...{ FirstPage.NavigateUrl = ""; PrevPage.NavigateUrl = ""; NextPage.NavigateUrl = ""; LastPaeg.NavigateUrl = ""; } if (CurPage <= 1 && pds.PageCount > 1) ...{ FirstPage.NavigateUrl = ""; PrevPage.NavigateUrl = ""; } if (CurPage >= pds.PageCount) ...{ NextPage.NavigateUrl = ""; LastPaeg.NavigateUrl = ""; } } catch (Exception error) ...{ Response.Write(error.ToString()); } finally ...{ } } public void Initialize(string ConnectionString, DataList DataPanl, string SelectCommand, string PageUrl) ...{ OleDbConnection conn = new OleDbConnection(ConnectionString); conn.Open(); OleDbDataAdapter oda = new OleDbDataAdapter(SelectCommand, conn); DataSet ds = new DataSet(); oda.Fill(ds); conn.Close(); try ...{ PagedDataSource pds = new PagedDataSource(); pds.DataSource = ds.Tables[0].DefaultView; pds.AllowPaging = true; pds.PageSize = 5; int CurPage; if (Request.QueryString["Page"] != null) ...{ CurPage = Convert.ToInt32(Request.QueryString["page"]); } else ...{ CurPage = 1; } pds.CurrentPageIndex = CurPage - 1; DataPanl.DataSource = pds; DataPanl.DataBind(); RecordCount.Text = pds.DataSourceCount.ToString(); PageCount.Text = pds.PageCount.ToString(); Pageindex.Text = CurPage.ToString(); Literal1.Text = PageList(pds.PageCount, CurPage, PageUrl); FirstPage.NavigateUrl = PageUrl + "page=1"; PrevPage.NavigateUrl = PageUrl + "page=" + (CurPage - 1); NextPage.NavigateUrl = PageUrl + "page=" + (CurPage + 1); LastPaeg.NavigateUrl = PageUrl + "page=" + pds.PageCount.ToString(); if (CurPage <= 1 && pds.PageCount <= 1) ...{ FirstPage.NavigateUrl = ""; PrevPage.NavigateUrl = ""; NextPage.NavigateUrl = ""; LastPaeg.NavigateUrl = ""; } if (CurPage <= 1 && pds.PageCount > 1) ...{ FirstPage.NavigateUrl = ""; PrevPage.NavigateUrl = ""; } if (CurPage >= pds.PageCount) ...{ NextPage.NavigateUrl = ""; LastPaeg.NavigateUrl = ""; } } catch (Exception error) ...{ Response.Write(error.ToString()); } finally ...{ } } public void Initialize(string ConnectionString, GridView DataPanl, string SelectCommand, string PageUrl) ...{ OleDbConnection conn = new OleDbConnection(ConnectionString); conn.Open(); OleDbDataAdapter oda = new OleDbDataAdapter(SelectCommand, conn); DataSet ds = new DataSet(); oda.Fill(ds); conn.Close(); try ...{ PagedDataSource pds = new PagedDataSource(); pds.DataSource = ds.Tables[0].DefaultView; pds.AllowPaging = true; pds.PageSize = 5; int CurPage; if (Request.QueryString["Page"] != null) ...{ CurPage = Convert.ToInt32(Request.QueryString["page"]); } else ...{ CurPage = 1; } pds.CurrentPageIndex = CurPage - 1; DataPanl.DataSource = pds; DataPanl.DataBind(); RecordCount.Text = pds.DataSourceCount.ToString(); PageCount.Text = pds.PageCount.ToString(); Pageindex.Text = CurPage.ToString(); Literal1.Text = PageList(pds.PageCount, CurPage, PageUrl); FirstPage.NavigateUrl = PageUrl + "page=1"; PrevPage.NavigateUrl = PageUrl + "page=" + (CurPage - 1); NextPage.NavigateUrl = PageUrl + "page=" + (CurPage + 1); LastPaeg.NavigateUrl = PageUrl + "page=" + pds.PageCount.ToString(); if (CurPage <= 1 && pds.PageCount <= 1) ...{ FirstPage.NavigateUrl = ""; PrevPage.NavigateUrl = ""; NextPage.NavigateUrl = ""; LastPaeg.NavigateUrl = ""; } if (CurPage <= 1 && pds.PageCount > 1) ...{ FirstPage.NavigateUrl = ""; PrevPage.NavigateUrl = ""; } if (CurPage >= pds.PageCount) ...{ NextPage.NavigateUrl = ""; LastPaeg.NavigateUrl = ""; } } catch (Exception error) ...{ Response.Write(error.ToString()); } finally ...{ } } public void Initialize(string ConnectionString, DataGrid DataPanl, string SelectCommand, string PageUrl) ...{ OleDbConnection conn = new OleDbConnection(ConnectionString); conn.Open(); OleDbDataAdapter oda = new OleDbDataAdapter(SelectCommand, conn); DataSet ds = new DataSet(); oda.Fill(ds); conn.Close(); try ...{ PagedDataSource pds = new PagedDataSource(); pds.DataSource = ds.Tables[0].DefaultView; pds.AllowPaging = true; pds.PageSize = 5; int CurPage; if (Request.QueryString["Page"] != null) ...{ CurPage = Convert.ToInt32(Request.QueryString["page"]); } else ...{ CurPage = 1; } pds.CurrentPageIndex = CurPage - 1; DataPanl.DataSource = pds; DataPanl.DataBind(); RecordCount.Text = pds.DataSourceCount.ToString(); PageCount.Text = pds.PageCount.ToString(); Pageindex.Text = CurPage.ToString(); Literal1.Text = PageList(pds.PageCount, CurPage, PageUrl); FirstPage.NavigateUrl = PageUrl + "page=1"; PrevPage.NavigateUrl = PageUrl + "page=" + (CurPage - 1); NextPage.NavigateUrl = PageUrl + "page=" + (CurPage + 1); LastPaeg.NavigateUrl = PageUrl + "page=" + pds.PageCount.ToString(); if (CurPage <= 1 && pds.PageCount <= 1) ...{ FirstPage.NavigateUrl = ""; PrevPage.NavigateUrl = ""; NextPage.NavigateUrl = ""; LastPaeg.NavigateUrl = ""; } if (CurPage <= 1 && pds.PageCount > 1) ...{ FirstPage.NavigateUrl = ""; PrevPage.NavigateUrl = ""; } if (CurPage >= pds.PageCount) ...{ NextPage.NavigateUrl = ""; LastPaeg.NavigateUrl = ""; } } catch (Exception error) ...{ Response.Write(error.ToString()); } finally ...{ } } public string PageList(int Pagecount, int Pageindex, string PageUrl) ...{ StringBuilder sb = new StringBuilder(); sb.Append("<select id="Page_Jump" name="Page_Jump" οnchange="window.location='" + PageUrl + "page='+ this.options[this.selectedIndex].value + '';">"); for (int i = 1; i <= Pagecount; i++) ...{ if (Pageindex == i) sb.Append("<option value='" + i + "' selected>" + i + "</option>"); else sb.Append("<option value='" + i + "'>" + i + "</option>"); } sb.Append("</select>"); return sb.ToString(); }}