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


    一、预览效果


    二、前台控件呈现部分
    三、后置代码部分(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;

    public partial class admin_LeaveMessages : System.Web.UI.Page
    {
        
    protected void Page_Load(object sender, EventArgs e)
        
    {
            
    if (!Page.IsPostBack)
            
    {
                NewsBind();
            }

        }

        
    private void NewsBind()//repeater分页并绑定
        {
            
    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
            
    {
                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)
                
    {
                    CurPage 
    = Convert.ToInt32(Request.QueryString["page"]);
                }

                
    else
                
    {
                    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为参数


                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)
                
    {
                    FirstPage.NavigateUrl 
    = "";
                    PrevPage.NavigateUrl 
    = "";
                    NextPage.NavigateUrl 
    = "";
                    LastPaeg.NavigateUrl 
    = "";
                    
    /**//*
                    FirstPage.Visible = false;
                    PrevPage.Visible = false;
                    NextPage.Visible = false;
                    LastPaeg.Visible = false;
                    
    */

                }

                
    if (CurPage <= 1 && objPage.PageCount > 1)
                
    {
                    FirstPage.NavigateUrl 
    = "";
                    PrevPage.NavigateUrl 
    = "";
                    
    /**//*
                    FirstPage.Visible = false;
                    PrevPage.Visible = false;
                    
    */



                }

                
    if (CurPage >= objPage.PageCount)
                
    {
                    NextPage.NavigateUrl 
    = "";
                    LastPaeg.NavigateUrl 
    = "";
                    
    /**//*
                    NextPage.Visible = false;
                    LastPaeg.Visible = false;
                    
    */

                }

            }

            
    catch(Exception error)
            
    {
                Response.Write(error.ToString());
            }

            
    finally
            
    {
                conn.Close();
            }

        }

        
    private string PageList(int Pagecount, int Pageindex)//private string Jump_List(int Pagecount , int Pageindex , long L_Manage)//带参数的传递
        {
            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 + '';\">");

            
    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();
        }


       
    }

  • 相关阅读:
    centos6下安装配置DNS(bind)
    centos6下安装配置NFS
    如何在kettle里面加载hadoop
    jQuery练习JavaScript事件与事件对象
    摆上殷勤的工作&职场用祷文
    Ajax自动完成(autocomplete)响应文本框输入后显示模糊数据列表
    未来的书香
    重要的计算机学习资料(累计中)
    W4F学习笔记之一
    软件测试重要资料汇集
  • 原文地址:https://www.cnblogs.com/jiangyuxuan/p/843473.html
Copyright © 2020-2023  润新知