Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4020748
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:16:01+00:00 2026-05-20T10:16:01+00:00

I develop a custom data pager control. Its previous and next hyperLink buttons don’t

  • 0

I develop a custom data pager control. Its “previous” and “next” hyperLink buttons don’t work properly and I don’t understand why.

    <asp:Repeater ID="rpt" runat="server">
<HeaderTemplate>
    <asp:LinkButton ID="lnkbFirst" CommandName="<%#PageChangedItemCommand %>" CommandArgument="1" runat="server">&laquo;</asp:LinkButton>&nbsp;
     <asp:LinkButton ID="lnkbPrevious" CommandName="<%#PageChangedItemCommand %>" CommandArgument="<%#PreviousPageIndex%>"  runat="server">&lt;</asp:LinkButton>&nbsp;
 </HeaderTemplate>   
<ItemTemplate> 
    <asp:LinkButton  CommandName="<%#PageChangedItemCommand %>" CommandArgument="<%#Container.DataItem.ToString()%>"  ID="p" runat="server" ><%#Container.DataItem.ToString()%>&nbsp;</asp:LinkButton>
</ItemTemplate>

<FooterTemplate>
     <asp:LinkButton ID="lnkbNext" CommandName="<%#PageChangedItemCommand %>" CommandArgument="<%#NextPageIndex%>"  runat="server">&gt;</asp:LinkButton>&nbsp;
     <asp:LinkButton ID="lnkbLast" CommandName="<%#PageChangedItemCommand %>" CommandArgument="<%#PagesCount%>" runat="server">&raquo;</asp:LinkButton>
</FooterTemplate>
</asp:Repeater>



public partial class Pager : System.Web.UI.UserControl
    {
        public int CurrentPage { get; set; }
        public int PageSize { get; set; }
        public int DataItemsCount { get; set; }


        private int _pagesCount;
        public int PagesCount
        {

            get
            {
                if (DataItemsCount % PageSize == 0)
                    return _pagesCount = (DataItemsCount / PageSize);

                else
                    return _pagesCount = ((DataItemsCount / PageSize) + 1);
            }

            private set
            {
                _pagesCount = value;
            }
        }

        public event EventHandler<PageChangedEventArgs> PageChanged;
        protected const string PageChangedItemCommand = "PageChanged";
        private const string CurrentPageCssStyle = "font-weight:bold; font-size:15px;";

        private void RaiseEvent(int currentPage)
        {
            if (PageChanged != null)
                PageChanged(this, new PageChangedEventArgs(currentPage));
        }

        protected List<int> DataSource
        {
            get
            {
                List<int> pages = new List<int>();
                for (int i = 1; i <= PagesCount; i++)
                    pages.Add(i);

                return pages;
            }
        }

        protected int NextPageIndex { get { return CurrentPage + 1; } }
        protected int PreviousPageIndex { get { return CurrentPage -1; } }

        public Pager()
        {
            CurrentPage = 1;
            PageSize = 1;
            DataItemsCount = 1;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            rpt.ItemCommand += new RepeaterCommandEventHandler(rpt_ItemCommand);
            rpt.DataSource = DataSource;
            rpt.DataBind();

          //  
            if (!Page.IsPostBack)
            {
                CurrentPageSetCssStyle(CurrentPageCssStyle);
                // SetupCommandArguments();
            }
        }

        void rpt_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == PageChangedItemCommand)
            {
                CurrentPage = int.Parse(e.CommandArgument.ToString());
                CurrentPageSetCssStyle(CurrentPageCssStyle);
               // SetupCommandArguments();
                RaiseEvent(CurrentPage);

            }
        }



        private void CurrentPageSetCssStyle(string style)
        {
            foreach (RepeaterItem item in rpt.Items)
            {
                LinkButton lnkButton = item.FindControl("p") as LinkButton;
                if (lnkButton != null)
                {
                    if (lnkButton.CommandArgument == CurrentPage.ToString())
                        lnkButton.Attributes.Add("style", style);
                }
            }
          //  SetupCommandArguments();
        }



        void SetupCommandArguments()
        {
            LinkButton lnkbPrevious = rpt.Controls[0].Controls[0].FindControl("lnkbPrevious") as LinkButton;
            if (lnkbPrevious != null)
                lnkbPrevious.CommandArgument = (CurrentPage - 1).ToString();

            LinkButton lnkbNext = rpt.Controls[rpt.Controls.Count - 1].Controls[0].FindControl("lnkbNext") as LinkButton;
            if (lnkbPrevious != null)
                lnkbPrevious.CommandArgument = (CurrentPage + 1).ToString();
        }

    }

I need to develop my own paging light control. Don’t suggest me to use other paging controls.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:16:02+00:00Added an answer on May 20, 2026 at 10:16 am

    I’ve had to do a custom pager in the last few days, but I went about it slightly differently.

    I chose to use two repeaters:
    1. This one was for the paging

    <div class="searchResultsPaging" runat="server">
            <asp:Repeater ID="Paging" runat="server">
                <ItemTemplate>
                    <a href='<%# Eval("PageUrl") %>' class='<%# (Convert.ToBoolean(Eval("IsCurrent")) == true)? "pagingButtonOff" : "pagingButtonOn" %>'>
                        <%# Eval("PageText") %></a>
                </ItemTemplate>
            </asp:Repeater>
        </div>
    

    2. Was for the items I’m display

    <asp:Repeater ID="Properties" runat="server">
            <ItemTemplate>
                <div class="propertyCard">
                    <div class="propertyTitle">
                        <a href='/property/<%# Eval("Id") %>'>
                            <%# Eval("Title") %></a></div>
                    <div class="propertySuburb">
                        <%# Eval("Suburb") %></div>
                    <img src='/_Remove/SamplePropertyImages/<%# Eval("PriorityImage") %>' width="190"
                        height="143" alt='Property for sale in <%# Eval("Suburb")%>' />
                    <div class="propertyFeatures">
                        <img src="/_Remove/Icons/Bed.gif" alt='<%# Eval("Suburb") %>, <%# Eval("City") %> property has <%# Eval("Bedrooms") %> bedrooms.' /><%# Eval("Bedrooms") %><img
                            src="/_Remove/Icons/Bath.gif" alt='<%# Eval("Suburb") %>, <%# Eval("City") %> property has <%# Eval("Bathrooms") %> bedrooms.' /><%# Eval("Bathrooms") %></div>
                    <div class="propertyPrice">
                        <%# Eval("Price","{0:###,##0.00}") %>
                    </div>
                    <a href="#">View Property Details</a>
                </div>
            </ItemTemplate>
        </asp:Repeater>
    

    During binding, my business logic returned a list of properties and a total count. From there it was easy to bind and build the paging controls.

    Might not work for you since you’re looking for page next/back type functionality.

    Regards,
    Jacqueds

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I will soon work for a company project which will develop a custom .NET
We develop custom survey web sites and I am looking for a way to
I need to develop custom software to do surveys. Questions may be of multiple
I'm working with a CMS which allows you to develop your own custom controls
I would like to develop a custom application (multiple screens, complex processes) on top
I develop exclusively on VMs. I currently run Boot Camp on a MacBook Pro
I develop an extension module for Guile, written in C. This extension module embeds
We develop Win32 application that access to SQL 2005 database through Linq to SQL.
I develop and manage about 45 WindowsCE5 devices. Updating applications on the devices is
I develop a number of desktop Java applications using Swing, and while Swing is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.