求个高效的repeater分页源代码!
做为参考!

解决方案 »

  1.   

    楼主:
      有没有做过“一个没有依靠控件的分页代码,输出的数据也没有依靠控件的分页代码弄过没有?”
    我做的效果如下: 
    ASPX页面就一个: <%=table%> 
    aspx.cs页面代码: 
    ----------------------------------------------------- 
    #region 切换图 
        public string table = "", id=""; 
        private void BindQieHuanTu() 
        { 
            con = new SqlConnection(zglh.returnSqlstr()); 
            cmd = con.CreateCommand(); 
            cmd.CommandText = "select * from guanggao where gg_type='首页滚动图片' and gg_if='是' order by gg_sort asc,gg_time desc"; 
          
            try 
            { 
                con.Open(); 
                SqlDataReader dr = cmd.ExecuteReader();          
              
                int i = 1; 
                while (dr.Read()) 
                { 
                    string pic = Convert.ToString(dr["gg_pic"]); 
                    string gg_id = dr["gg_id"].ToString(); 
                    //string id = string.Empty; 
                    string pic1 = "admin/guanggao/" + pic; 
                    string pic2 = " <td width=\"278\" height=\"96\" valign=\"top\"> <table width=\"274\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#FFFFFF\"> <tr> <td width=\"97\" align=\"center\" valign=\"middle\"> <a href='" + dr["gg_id"] + "'> <img src=\"" + pic1 + "\" width=\"70\" height=\"60\" border=0 /> </a> </td> <td width=\"177\" align=\"left\" class=\"hg\">英国《每日电讯报》26日报道道 <br />英国女子坦娅·迪克森堪称爱迪 <br />克森堪称爱迪克森堪称爱迪克森 <br />堪称爱迪克森堪... </td> </tr> </table> </td>"; 
                    table += pic2; 
                    if (i % 2 == 0) 
                    { 
                        table += " <td width=\"98\" align=\"center\" valign=\"top\"> <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> <tr> <td height=\"65\">&nbsp; </td> </tr> <tr> <td> <a href='ceshi1.aspx?id=" + id + "," + dr["gg_id"] + "'> <img src=\"images/db.jpg\" width=\"97\" height=\"27\" border=0 /> </a> </td> </tr> </table> </td> </tr> <tr>"; 
                    } 
                    else 
                    { 
                        id = gg_id; 
                    } 
                    i++;                          
                }          
                dr.Close(); 
                con.Close(); 
            } 
            catch 
            { 
                con.Close(); 
            } 
        } 
    #endregion 
    --------------------------------------------------------------------------------------------- 
    请问这种输出数据没有依靠控件,分页也不依靠控件的分页效果怎么做。发出效果代码,谢谢
      

  2.   

    1、用PageDataSource类来分页
    源码:
    http://www.cnblogs.com/xuanfeng/archive/2007/04/08/704366.html2、普通方式
    http://www.webasp.net/article/28/27885.htm3、可以使用AspNetPage来分页,使用方便,用存储过程方式调用,效率挺高的
    直接下一个AspNetPage控件就行了,是一个开源的.而且使用方法到处都能找到,只有这个最简单
      

  3.   

    PageDataSource来做的话,我输出的数据没有用控件绑定,我怎么绑定数据循环呀
            PDS.DataSource =((DataTable)Session["data"]).DefaultView;
            PDS.CurrentPageIndex = index;
            PDS.AllowPaging = true;
            PDS.PageSize = 20;
            this.Repeater2.DataSource = PDS;
            this.Repeater2.DataBind();就像这里
      

  4.   

    ------------------------------------- 
    Pagination.aspx 
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Pagination.aspx.cs" Inherits="Pagination" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head runat="server"> 
        <title>无标题页 </title> 
    </head> 
    <body> 
        <form id="form1" runat="server"> 
            <div align="center"> 
                <asp:Literal ID="paginationResult" runat="server"> </asp:Literal> 
                <asp:Literal ID="paginationInfo" runat="server"> </asp:Literal> 
            </div> 
        </form> 
    </body> 
    </html> 
    ------------------------------------- 
    Pagination.aspx.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.Text; public partial class Pagination : System.Web.UI.Page 

        protected void Page_Load(object sender, EventArgs e) 
        { 
            PaginationMethod(); 
        }     protected void PaginationMethod()//分页程序 
        { 
            int totalCount = 300; // 总记录数,可作为此方法的参数 
            int pageSize = 20; // 每页记录数,可作为此方法的参数         string url = Request.Url.AbsoluteUri.Split('?')[0]; // 基地址              int currentPage = 1; // 当前页数 
            if (Request["currentPage"] != null && Request["currentPage"] != "") 
            { 
                currentPage = int.Parse(Request["currentPage"].ToString().Trim()); 
            }         int totalPage = (totalCount - 1) / pageSize + 1; //总页数 
            int startPage = 1; // 起始页数 
            int endPage = totalPage; //结束页数         // 分页信息 
            this.paginationInfo.Text = "共 <font color=red>" + totalCount + " </font> 条记录"; 
            this.paginationInfo.Text += ",分 <font color=red>" + totalPage + " </font> 页显示";         // 校验参数 
            if ((totalCount < 0) || (pageSize < 1)) 
            { 
                return; 
            } 
            if (currentPage < 1) 
            { 
                currentPage = 1; 
            } 
            if (currentPage > totalPage) 
            { 
                currentPage = totalPage; 
            }         // 设置起始页数和结束页数 
            if (totalPage <= 9) 
            { 
                startPage = 1; 
                endPage = totalPage; 
            } 
            else 
            { 
                if (currentPage <= 5) 
                { 
                    startPage = 1; 
                    endPage = 9; 
                } 
                else 
                { 
                    startPage = currentPage - 4; 
                    endPage = currentPage + 4 < totalPage ? currentPage + 4 : totalPage; 
                } 
            }         // 判断首页、上一页、下一页、尾页的链接是否可用 
            bool firstIsEnable = true; 
            bool preIsEnable = true; 
            bool nextIsEnable = true; 
            bool lastIsEnable = true; 
            if (totalPage == 1) 
            { 
                firstIsEnable = false; 
                preIsEnable = false; 
                nextIsEnable = false; 
                lastIsEnable = false; 
            } 
            else if (currentPage == 1) 
            { 
                firstIsEnable = false; 
                preIsEnable = false; 
            } 
            else if (currentPage == totalPage) 
            { 
                nextIsEnable = false; 
                lastIsEnable = false; 
            }         // 生成分页结果 
            StringBuilder sResult = new StringBuilder(); 
            // 1.首页 
            sResult.Append(LinkStyle(url, 1, "首页", firstIsEnable)); 
            // 2.上一页 
            sResult.Append(LinkStyle(url, currentPage - 1, "&lt;&lt;", preIsEnable)); 
            // 3.中间页数 
            for (int i = startPage; i <= endPage; i++) 
            { 
                bool linkIsEnable = true; 
                if (i == currentPage) 
                { 
                    linkIsEnable = false; 
                } 
                sResult.Append(LinkStyle(url, i, i.ToString(), linkIsEnable)); 
            } 
            // 4.下一页 
            sResult.Append(LinkStyle(url, currentPage + 1, "&gt;&gt;", nextIsEnable)); 
            // 5.尾页 
            sResult.Append(LinkStyle(url, totalPage, "尾页", lastIsEnable)); 
            this.paginationResult.Text = sResult.ToString(); 
        } 
        protected string LinkStyle(string url, int pageIndex ,string id,bool linkIsEnable) // 这里可改变分页样式 
        { 
            string result; 
            if (linkIsEnable) 
            { 
                result = " <span> <a href=\"" + url + "?currentPage=" + pageIndex + "\">" + id + " </a> </span> "; 
            } 
            else 
            { 
                result = " <span>" + id + " </span> "; 
            } 
            return result; 
        } 

    ------------------------------------- 
    然后再找个通用存储过程,结合起来很好使的
      

  5.   

    建议用第三方分布控件。简单,功能全面。aspnetpager
      

  6.   

    Repeater自定义分页 + 排序 + 全选删除
    http://blog.csdn.net/amandag/archive/2008/08/05/2773541.aspx
      

  7.   

    PagedDataSource实例.DataSource=DataView实例
    Repeater实例.DataSource=PagedDataSource实例;
    Repeate实r实例.DataBind();
      

  8.   


    程序员总是有自己造轮子的冲动
    建议使用AspNetPage
      

  9.   

    用分页控件
    http://www.cnblogs.com/csharp-net/archive/2007/11/26/973093.html