Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.net中的多个页面(如google结果)_Asp.net_Pagination - Fatal编程技术网

ASP.net中的多个页面(如google结果)

ASP.net中的多个页面(如google结果),asp.net,pagination,Asp.net,Pagination,我正在努力做到以下几点 我的asp页面中有一个动态表 我想用多页的方式显示表格,比如谷歌搜索结果 有什么有用的建议吗 注: 我不想使用gridview 因此,还有其他方法吗???您可以使用jquery插件和该插件来实现这一点。它将在标准html表上工作,并具有许多选项,如交替行高亮显示、排序等。它取决于返回的最大记录数。最有效的方法是 将页码实现为查询参数不同的链接 根据查询参数,在服务器端,仅获取与该页面对应的记录。如果页面大小为10,当前页面为2,则只从服务器获取11,20条记录并将其绑定到

我正在努力做到以下几点 我的asp页面中有一个动态表 我想用多页的方式显示表格,比如谷歌搜索结果 有什么有用的建议吗 注: 我不想使用gridview
因此,还有其他方法吗???

您可以使用jquery插件和该插件来实现这一点。它将在标准html表上工作,并具有许多选项,如交替行高亮显示、排序等。

它取决于返回的最大记录数。最有效的方法是

  • 将页码实现为查询参数不同的链接
  • 根据查询参数,在服务器端,仅获取与该页面对应的记录。如果页面大小为10,当前页面为2,则只从服务器获取11,20条记录并将其绑定到html表

  • 如果您使用的是LINQtoSQL,请使用Take和SKIP方法,如中所示

  • 如果您使用的是直接SQL查询或存储过程,请使用RowID获取该页面的记录


  • 如果您希望输出比GridView提供更多的灵活性,请查看Repeater

    由于中继器不直接实现分页,因此您必须提供自己的“下一个”和“上一个”按钮。正如Sundararajan S所指出的,如果您有许多记录,您将希望使用当前页码和页面大小仅将当前页面的记录返回到浏览器,而不是全部记录

    下面是一个示例(我不知道您的数据源是什么样的,所以我只使用了一个列表作为示例。用更合适的内容替换。)

    希望有帮助

    Default.aspx:

        <asp:Button ID="PrevPageButton" runat="server" Text="Prev" 
            onclick="PrevPageButton_Click" />
        <asp:Label ID="CurrentPageLabel" runat="server" />
        <asp:Button ID="NextPageButton" runat="server" Text="Next" 
            onclick="NextPageButton_Click" />
    
    
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <h2> <%# Eval("Name") %> </h2>
                <p>
                <%# Eval("Description") %>
                </p>
            </ItemTemplate>
        </asp:Repeater>
    
    
    
    

    Default.aspx.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace RepeaterPaging
    {
        public partial class _Default : System.Web.UI.Page
        {
            private const int PageSize = 10;
            private const int MaxPage = 4;
    
    
            public int CurrPage
            {
                get
                {
                    if (this.ViewState["CurrPage"] == null )
                        this.ViewState["CurrPage"] = 0;
    
                    return (int) this.ViewState["CurrPage"];
                }
    
                set { this.ViewState["CurrPage"] = value; }
            }
    
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    BindItems();
                }
    
            }
    
            protected void BindItems()
            {
                int currPage = CurrPage;
    
                List<Book> books = new List<Book>();
                int startItem = (currPage * PageSize) + 1;
                for (int i = startItem; i < startItem+PageSize; i++)
                {
                    books.Add(new Book("Title " + i, "Description " + i + " ..................."));
                }
    
                Repeater1.DataSource = books;
                Repeater1.DataBind();
    
                CurrentPageLabel.Text =
                    string.Format(" Page {0} of {1} ", CurrPage + 1, MaxPage + 1);
            }
    
            protected void NextPageButton_Click(object sender, EventArgs e)
            {
                if (CurrPage < MaxPage)
                {
                    CurrPage++;
                    BindItems();
                }
            }
    
            protected void PrevPageButton_Click(object sender, EventArgs e)
            {
                if (CurrPage > 0)
                {
                    CurrPage--;
                    BindItems();
                }
            }
        }
    
        public class Book
        {
            public string Name { get; set; }
            public string Description { get; set; }
    
            public Book(string name, string desc)
            {
                Name = name;
                Description = desc;
            }
        }
    }
    
    使用系统;
    使用System.Collections.Generic;
    使用System.Linq;
    使用System.Web;
    使用System.Web.UI;
    使用System.Web.UI.WebControl;
    名称空间重复页面
    {
    公共部分类\u默认值:System.Web.UI.Page
    {
    private const int PageSize=10;
    private const int MaxPage=4;
    公共网页
    {
    得到
    {
    if(this.ViewState[“CurrPage”]==null)
    this.ViewState[“CurrPage”]=0;
    返回(int)this.ViewState[“CurrPage”];
    }
    设置{this.ViewState[“CurrPage”]=value;}
    }
    受保护的无效页面加载(对象发送方、事件参数e)
    {
    如果(!IsPostBack)
    {
    BindItems();
    }
    }
    受保护的项目()
    {
    int currPage=currPage;
    列表书籍=新列表();
    int startItem=(currPage*PageSize)+1;
    for(inti=startItem;i0)
    {
    第页--;
    BindItems();
    }
    }
    }
    公共课堂用书
    {
    公共字符串名称{get;set;}
    公共字符串说明{get;set;}
    公共图书(字符串名称、字符串描述)
    {
    名称=名称;
    描述=描述;
    }
    }
    }
    
    如果您没有使用GridView,您使用的是什么?这些建议将取决于某种程度的实施细节。例如,[无论您使用什么]是否支持ObjectDataSource或SqlDataSource(两者都支持分页)。我使用的是普通表(Html),但它是动态的,我的意思是它会根据结果增长,我将展示其缺点,因为他将不得不将所有结果发送到浏览器,其中许多结果不适合他的需要。他真的应该考虑使用LINQ和Take和Skip。对,根据表中的行数,可能会很慢。我会从一个普通的arraylist中获取我的结果,现在我只是把它们放在HTML表中,我想在多个页面上创建它