Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)
摘要:table width=“100%”border=“0”align=“center”cellpadding=“1”cellspacing=“1“bgcolor=“#D4D0C8”>;共同拥有<;页面<;HyperLink ID=“NextPage”runat=“server”Text=“Next Page”>;
一、预览效果
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第1张](https://www.cnblogs.com/images/cnblogs_com/zm235/Page.jpg)
二、前台控件呈现部分
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第2张](http://www.cnweblog.com/Images/OutliningIndicators/ContractedBlock.gif)
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第3张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<asp:repeater id="LeaveMessage" runat="server" >
<ItemTemplate>
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#D4D0C8">
<tr>
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第8张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<td width="85%" bgcolor="#FFFAFF"><div align="left"><%
#DataBinder.Eval(Container.DataItem, "sNewsTitle")%></div></td>
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第8张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<td width="15%" bgcolor="#FFFAFF" align="left"><%
#DataBinder.Eval(Container.DataItem, "dAddTime")%></td>
</tr>
</table>
<hr size="3px" width="90%"/>
</ItemTemplate>
</asp:repeater>
共有<asp:Literal ID="RecordCount" runat="server"></asp:Literal>条记录
共有<asp:Literal ID="PageCount" runat="server"></asp:Literal>页
当前第<asp:Literal ID="Pageindex" runat="server"></asp:Literal>页
<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>
跳转到<asp:Literal ID="Literal1" runat="server"></asp:Literal>页 三、后置代码部分(CS代码)
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.Data.SqlClient;
using System.Text;
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第4张](http://www.cnweblog.com/Images/OutliningIndicators/None.gif)
public partial class admin_LeaveMessages : System.Web.UI.Page
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第8张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第9张](http://www.cnweblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
protected void Page_Load(object sender, EventArgs e)
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (!Page.IsPostBack)
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
NewsBind();
}
}
private void NewsBind()//repeater分页并绑定
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string SqlStr = "select sNewsTitle,dAddTime from [News] order by dAddTime";
string connectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionSqlServer"].ToString();
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
SqlDataAdapter Adapter = new SqlDataAdapter(SqlStr, conn);
DataSet ds = new DataSet();
try
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Adapter.Fill(ds, "testTable");
PagedDataSource objPage = new PagedDataSource();
objPage.DataSource=ds.Tables["testTable"].DefaultView;
objPage.AllowPaging=true;
objPage.PageSize=3;
int CurPage;
if (Request.QueryString["Page"] != null)
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
CurPage = Convert.ToInt32(Request.QueryString["page"]);
}
else
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
CurPage = 1;
}
objPage.CurrentPageIndex = CurPage - 1;
LeaveMessage.DataSource=objPage;//这里更改控件名称
LeaveMessage.DataBind();//这里更改控件名称
RecordCount.Text = objPage.DataSourceCount.ToString();
PageCount.Text = objPage.PageCount.ToString();
Pageindex.Text = CurPage.ToString();
Literal1.Text = PageList(objPage.PageCount, CurPage);
//Literal1.Text = PageList(objPage.PageCount, Pageindex, L_Manage); //带参数的:LManage为参数
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第44张](http://www.cnweblog.com/Images/OutliningIndicators/InBlock.gif)
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第44张](http://www.cnweblog.com/Images/OutliningIndicators/InBlock.gif)
FirstPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=1";
PrevPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (CurPage - 1);
NextPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (CurPage + 1);
LastPaeg.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + objPage.PageCount.ToString();
if (CurPage <= 1 && objPage.PageCount <= 1)
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
FirstPage.NavigateUrl = "";
PrevPage.NavigateUrl = "";
NextPage.NavigateUrl = "";
LastPaeg.NavigateUrl = "";
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//*
FirstPage.Visible = false;
PrevPage.Visible = false;
NextPage.Visible = false;
LastPaeg.Visible = false;
*/
}
if (CurPage <= 1 && objPage.PageCount > 1)
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
FirstPage.NavigateUrl = "";
PrevPage.NavigateUrl = "";
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//*
FirstPage.Visible = false;
PrevPage.Visible = false;
*/
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第44张](http://www.cnweblog.com/Images/OutliningIndicators/InBlock.gif)
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第44张](http://www.cnweblog.com/Images/OutliningIndicators/InBlock.gif)
}
if (CurPage >= objPage.PageCount)
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
NextPage.NavigateUrl = "";
LastPaeg.NavigateUrl = "";
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//*
NextPage.Visible = false;
LastPaeg.Visible = false;
*/
}
}
catch(Exception error)
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Response.Write(error.ToString());
}
finally
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
conn.Close();
}
}
private string PageList(int Pagecount, int Pageindex)//private string Jump_List(int Pagecount , int Pageindex , long L_Manage)//带参数的传递
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
StringBuilder sb = new StringBuilder();
//下为带参数的传递
//sb.Append("<select id=\"Page_Jump\" name=\"Page_Jump\" onchange=\"window.location='" + Request.CurrentExecutionFilePath + "?page='+ this.options[this.selectedIndex].value + '&Org_ID=" + L_Manage + "';\">");
//不带参数的传递
sb.Append("<select id=\"Page_Jump\" name=\"Page_Jump\" onchange=\"window.location='" + Request.CurrentExecutionFilePath + "?page='+ this.options[this.selectedIndex].value + '';\">");
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第44张](http://www.cnweblog.com/Images/OutliningIndicators/InBlock.gif)
for (int i = 1; i <= Pagecount; i++)
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第45张](http://www.cnweblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
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();
}
![Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)第44张](http://www.cnweblog.com/Images/OutliningIndicators/InBlock.gif)
}
免责声明:文章转载自《Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。
上篇VC6和VS2008中C++编译器差异让C#程序run anywhere 脱离.net Framework框架环境下篇
宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=