[Solved] ASP.NET: Could anyone provide some C# paging codes in Repeater or ListView controls for me to learn [closed]


Here is a pager control that I created to drop into the PagerTemplate of a GridView. It’s not the most complicated stuff, but it shows how a pager control can ‘see’ the grid that it belongs to and render a dropdown to jump to a specific page.

DataPager.ascx

<%@ Control Language="C#" AutoEventWireup="true" EnableViewState="true" CodeFile="DataPager.ascx.cs" Inherits="Resources_Controls_DataPager" %>
<div>
    <div style="float:right;">
        <asp:ImageButton id="PageFirst"
            CommandName="Page"
            CommandArgument="First"
            runat="server" />
        <asp:ImageButton id="PagePrev"
            CommandName="Page"
            CommandArgument="Prev"
             runat="server" />
        &nbsp;&nbsp;Page 
        <asp:DropDownList id="pagesDropDown"
            autopostback="true"
            OnSelectedIndexChanged="pagesDropDown_SelectedIndexChanged"
            runat="server" />
        <asp:Label id="pageTotalPages" runat="server" />&nbsp;&nbsp;
        <asp:ImageButton ID="PageNext"
            CommandName="Page"
            CommandArgument="Next"
            runat="server" />
        <asp:ImageButton ID="PageLast"
            CommandName="Page"
            CommandArgument="Last"
            runat="server" />
    </div>
    <div style="clear:both;"></div>
</div>

DataPager.ascx.cs

public partial class Resources_Controls_DataPager : System.Web.UI.UserControl
{
    #region Property: ParentGrid
    public GridView ParentGrid
    {
        get { return (GridView)Parent.Parent.Parent.Parent; }
    }
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        FillPage();
    }

    public void FillPage()
    {
        if (ParentGrid != null && pagesDropDown.Items.Count == 0)
        {
            pagesDropDown.Items.Clear();
            for (int ix = 0; ix < ParentGrid.PageCount; ix++)
            {
                ListItem item = new ListItem((ix + 1).ToString());
                item.Selected = (ix == ParentGrid.PageIndex);
                pagesDropDown.Items.Add(item);
            }

            if (pagesDropDown.Items.Count == 0)
                pagesDropDown.Items.Add(new ListItem("0"));

            pageTotalPages.Text = String.Format("of {0}", ParentGrid.PageCount);
        }
    }

    protected void pagesDropDown_SelectedIndexChanged(object sender, EventArgs e)
    {
        ParentGrid.PageIndex = pagesDropDown.SelectedIndex;
    }
}

0

solved ASP.NET: Could anyone provide some C# paging codes in Repeater or ListView controls for me to learn [closed]