Asp.net2.0 VS 2005下的repeater控件本功能分页实例(共有 条记录 共有几页 当前第 页 首页,上一页,下一页,尾页 DropDownList跳转)...

一、预览效果

Page.jpg
二、前台控件呈现部分
ContractedBlock.gifExpandedBlockStart.gif
None.gif<asp:repeater id="LeaveMessage" runat="server" >
None.gif
<ItemTemplate>
None.gif
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#D4D0C8">
None.gif
<tr>
ExpandedBlockStart.gifContractedBlock.gif
<td width="85%" bgcolor="#FFFAFF"><div align="left"><%dot.gif#DataBinder.Eval(Container.DataItem, "sNewsTitle")%></div></td>
ExpandedBlockStart.gifContractedBlock.gif
<td width="15%" bgcolor="#FFFAFF" align="left"><%dot.gif#DataBinder.Eval(Container.DataItem, "dAddTime")%></td>
None.gif
</tr>
None.gif
</table>
None.gif
<hr size="3px" width="90%"/>
None.gif
</ItemTemplate> 
None.gif
</asp:repeater>
None.gif共有
<asp:Literal ID="RecordCount" runat="server"></asp:Literal>条记录
None.gif共有
<asp:Literal ID="PageCount" runat="server"></asp:Literal>
None.gif当前第
<asp:Literal ID="Pageindex" runat="server"></asp:Literal>
None.gif
<asp:HyperLink ID="FirstPage" runat="server" Text="首页"></asp:HyperLink>
None.gif
<asp:HyperLink ID="PrevPage" runat="server" Text="上一页"></asp:HyperLink>
None.gif
<asp:HyperLink ID="NextPage" runat="server" Text="下一页"></asp:HyperLink>
None.gif
<asp:HyperLink ID="LastPaeg" runat="server" Text="尾页"></asp:HyperLink>
None.gif跳转到
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
三、后置代码部分(CS代码)
None.gifusing System;
None.gif
using System.Data;
None.gif
using System.Configuration;
None.gif
using System.Collections;
None.gif
using System.Web;
None.gif
using System.Web.Security;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.WebControls.WebParts;
None.gif
using System.Web.UI.HtmlControls;
None.gif
using System.Data.SqlClient;
None.gif
using System.Text;
None.gif
None.gif
public partial class admin_LeaveMessages : System.Web.UI.Page
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (!Page.IsPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            NewsBind();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
private void NewsBind()//repeater分页并绑定
ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
InBlock.gif        
string SqlStr = "select sNewsTitle,dAddTime from [News] order by dAddTime";        
InBlock.gif        
string connectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionSqlServer"].ToString();
InBlock.gif        SqlConnection conn 
= new SqlConnection(connectionString);
InBlock.gif        conn.Open();
InBlock.gif        SqlDataAdapter Adapter 
= new SqlDataAdapter(SqlStr, conn);
InBlock.gif        DataSet ds 
= new DataSet();
InBlock.gif        
try
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Adapter.Fill(ds, 
"testTable");
InBlock.gif            PagedDataSource objPage 
= new PagedDataSource();
InBlock.gif            objPage.DataSource
=ds.Tables["testTable"].DefaultView;
InBlock.gif            objPage.AllowPaging
=true;
InBlock.gif            objPage.PageSize
=3;
InBlock.gif            
int CurPage;
InBlock.gif            
if (Request.QueryString["Page"!= null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                CurPage 
= Convert.ToInt32(Request.QueryString["page"]);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                CurPage 
= 1;
ExpandedSubBlockEnd.gif            }

InBlock.gif            objPage.CurrentPageIndex 
= CurPage - 1;
InBlock.gif            LeaveMessage.DataSource
=objPage;//这里更改控件名称
InBlock.gif
            LeaveMessage.DataBind();//这里更改控件名称
InBlock.gif
            RecordCount.Text = objPage.DataSourceCount.ToString();
InBlock.gif            PageCount.Text 
= objPage.PageCount.ToString();
InBlock.gif            Pageindex.Text 
= CurPage.ToString();
InBlock.gif            Literal1.Text 
= PageList(objPage.PageCount, CurPage);
InBlock.gif            
//Literal1.Text = PageList(objPage.PageCount, Pageindex, L_Manage); //带参数的:LManage为参数
InBlock.gif

InBlock.gif
InBlock.gif            FirstPage.NavigateUrl 
= Request.CurrentExecutionFilePath + "?page=1";
InBlock.gif            PrevPage.NavigateUrl 
= Request.CurrentExecutionFilePath + "?page=" + (CurPage - 1);
InBlock.gif            NextPage.NavigateUrl 
= Request.CurrentExecutionFilePath + "?page=" + (CurPage + 1);           
InBlock.gif            LastPaeg.NavigateUrl 
= Request.CurrentExecutionFilePath + "?page=" + objPage.PageCount.ToString();
InBlock.gif            
if (CurPage <= 1 && objPage.PageCount <= 1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                FirstPage.NavigateUrl 
= "";
InBlock.gif                PrevPage.NavigateUrl 
= "";
InBlock.gif                NextPage.NavigateUrl 
= "";
InBlock.gif                LastPaeg.NavigateUrl 
= "";
ExpandedSubBlockStart.gifContractedSubBlock.gif                
/**//**//**//*
InBlock.gif                FirstPage.Visible = false;
InBlock.gif                PrevPage.Visible = false;
InBlock.gif                NextPage.Visible = false;
InBlock.gif                LastPaeg.Visible = false;
ExpandedSubBlockEnd.gif                
*/

ExpandedSubBlockEnd.gif            }

InBlock.gif            
if (CurPage <= 1 && objPage.PageCount > 1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                FirstPage.NavigateUrl 
= "";
InBlock.gif                PrevPage.NavigateUrl 
= "";
ExpandedSubBlockStart.gifContractedSubBlock.gif                
/**//**//**//*
InBlock.gif                FirstPage.Visible = false;
InBlock.gif                PrevPage.Visible = false;
ExpandedSubBlockEnd.gif                
*/

InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if (CurPage >= objPage.PageCount)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                NextPage.NavigateUrl 
= "";
InBlock.gif                LastPaeg.NavigateUrl 
= "";
ExpandedSubBlockStart.gifContractedSubBlock.gif                
/**//**//**//*
InBlock.gif                NextPage.Visible = false;
InBlock.gif                LastPaeg.Visible = false;
ExpandedSubBlockEnd.gif                
*/

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
catch(Exception error)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write(error.ToString());
ExpandedSubBlockEnd.gif        }

InBlock.gif        
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            conn.Close();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
private string PageList(int Pagecount, int Pageindex)//private string Jump_List(int Pagecount , int Pageindex , long L_Manage)//带参数的传递
ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
InBlock.gif        StringBuilder sb 
= new StringBuilder();
InBlock.gif        
//下为带参数的传递
InBlock.gif        
//sb.Append("<select id=\"Page_Jump\" name=\"Page_Jump\" onchange=\"window.location='" + Request.CurrentExecutionFilePath + "?page='+ this.options[this.selectedIndex].value + '&Org_ID=" + L_Manage + "';\">");
InBlock.gif        
//不带参数的传递
InBlock.gif
        sb.Append("<select id=\"Page_Jump\" name=\"Page_Jump\" onchange=\"window.location='" + Request.CurrentExecutionFilePath + "?page='+ this.options[this.selectedIndex].value + '';\">");
InBlock.gif
InBlock.gif        
for (int i = 1; i <= Pagecount; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (Pageindex == i)
InBlock.gif                sb.Append(
"<option value='" + i + "' selected>" + i + "</option>");
InBlock.gif            
else
InBlock.gif                sb.Append(
"<option value='" + i + "'>" + i + "</option>");
ExpandedSubBlockEnd.gif        }

InBlock.gif        sb.Append(
"</select>");
InBlock.gif        
return sb.ToString();
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif   
ExpandedBlockEnd.gif}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值