Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Developing pager for winform application c#

$
0
0


i search google first to get any ready made sample for numeric pager for win form but unfortunately i found none. many exist for web application. so i have decided to develop my own. i have take one user control and i want to add some label on the user control at run time for simulating numeric pager link.

like << < 1 2 3 4 5 > >>

here is my code so far

public partial class PagerBar : UserControl
    {
        public PagerBar()
        {
            InitializeComponent();
        }

        int totalrecords = 0;
        public int TotalRecords
        {
            get { return totalrecords; }
            set { totalrecords = value; }
        }

        int recordsperpage = 0;
        public int RecordsPerPage
        {
            get { return recordsperpage; }
            set { recordsperpage = value; }
        }

        int curpage = 0;
        public int CurrentPage
        {
            get { return curpage; }
            set { curpage = value; }
        }

        int maxpagerlink = 0;
        public int MaxPagerLink
        {
            get { return maxpagerlink; }
            set { maxpagerlink = value; }
        }

        public bool HasPreviousPage
        {
            get
            {
                return (CurrentPage > 1);
            }
        }

        /// <summary>
        /// Gets the boolean value of next page
        /// </summary>
        public bool HasNextPage
        {
            get
            {
                return (CurrentPage + 1 <= RecordsPerPage);
            }
        }

        int pagecount = 0;
        public int PageCount
        {
            get
            {
                pagecount = TotalRecords > 0 ? (int)Math.Ceiling(TotalRecords / (double)RecordsPerPage) : 0;
                return pagecount;
            }

        }

        public void BuildPager(int CurrentPage)
        {
            if (CurrentPage >= MaxPagerLink)
            {

            }
            else
            {

            }
        }
    }

my first prev,next & prev button will be fixed. i will not generate these button at run time. i want to generate only numeric link like 1 2 3 4 5 etc at run time on user control.

one thing i need to fix that number of pager bar is will be fixed in my case and that is 5. i want to show always 5 pager link like 1 2 3 4 5 or 6 7 8 9 10 etc.

suppose total records is 36 and i want to show 10 records per page so 4 pager link i need to generate at run time. the right logic is not coming to my mind to generate pager link in such a way if number of records is 110 then everything should be handle properly. if total records is 110 and records per page is 10 then total pager bar should be 11 but i want to show only 5 at a time. first time 1 2 3 4 5 when user click on 5th pager bar and next time click on next button then pager link will be 6 7 8 9 10. this way i want to show pager link but right logic is not coming to mind to generate the way i want to display pager link. it will be great help if some one help me to handle generation of 5 pager link always.

Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>