Пример #1
0
        /// <devdoc>
        /// Creates the pager for NextPrev and NextPrev with First and Last styles
        /// </devdoc>
        private void CreateNumericPager(TableRow row, PagedDataSource pagedDataSource, bool addFirstLastPageButtons) {
            PagerSettings pagerSettings = PagerSettings;

            int pages = pagedDataSource.PageCount;
            int currentPage = pagedDataSource.CurrentPageIndex + 1;
            int pageSetSize = pagerSettings.PageButtonCount;
            int pagesShown = pageSetSize;
            int firstDisplayedPage = FirstDisplayedPageIndex + 1;   // first page displayed on last postback

            // ensure the number of pages we show isn't more than the number of pages that do exist
            if (pages < pagesShown)
                pagesShown = pages;

            // initialize to the first page set, i.e., pages 1 through number of pages shown
            int firstPage = 1;
            int lastPage = pagesShown;

            if (currentPage > lastPage) {
                // The current page is not in the first page set, then we need to slide the
                // range of pages shown by adjusting firstPage and lastPage
                int currentPageSet = (currentPage - 1) / pageSetSize;
                bool currentPageInLastDisplayRange = currentPage - firstDisplayedPage >= 0 && currentPage - firstDisplayedPage < pageSetSize;
                if (firstDisplayedPage > 0 && currentPageInLastDisplayRange) {
                    firstPage = firstDisplayedPage;
                }
                else {
                    firstPage = currentPageSet * pageSetSize + 1;
                }
                lastPage = firstPage + pageSetSize - 1;

                // now bring back lastPage into the range if its exceeded the number of pages
                if (lastPage > pages)
                    lastPage = pages;

                // if theres room to show more pages from the previous page set, then adjust
                // the first page accordingly
                if (lastPage - firstPage + 1 < pageSetSize) {
                    firstPage = Math.Max(1, lastPage - pageSetSize + 1);
                }
                FirstDisplayedPageIndex = firstPage - 1;
            }

            LinkButton button;

            if (addFirstLastPageButtons && currentPage != 1 && firstPage != 1) {
                string firstPageImageUrl = pagerSettings.FirstPageImageUrl;
                IButtonControl firstButton;
                TableCell cell = new TableCell();
                row.Cells.Add(cell);
                
                if (firstPageImageUrl.Length > 0) {
                    firstButton = new DataControlImageButton(this);
                    ((DataControlImageButton)firstButton).ImageUrl = firstPageImageUrl;
                    ((DataControlImageButton)firstButton).AlternateText = HttpUtility.HtmlDecode(pagerSettings.FirstPageText);
                    ((DataControlImageButton)firstButton).EnableCallback(BuildCallbackArgument(0));
                } else {
                    firstButton = new DataControlPagerLinkButton(this);
                    ((DataControlPagerLinkButton)firstButton).Text = pagerSettings.FirstPageText;
                    ((DataControlPagerLinkButton)firstButton).EnableCallback(BuildCallbackArgument(0));
                }
                firstButton.CommandName = DataControlCommands.PageCommandName;
                firstButton.CommandArgument = DataControlCommands.FirstPageCommandArgument;
                cell.Controls.Add((Control)firstButton);
            }

            if (firstPage != 1) {
                TableCell cell = new TableCell();
                row.Cells.Add(cell);
                
                button = new DataControlPagerLinkButton(this);
                button.Text = "...";
                button.CommandName = DataControlCommands.PageCommandName;
                button.CommandArgument = (firstPage - 1).ToString(NumberFormatInfo.InvariantInfo);
                ((DataControlPagerLinkButton)button).EnableCallback(BuildCallbackArgument(firstPage - 2));
                cell.Controls.Add(button);
            }

            for (int i = firstPage; i <= lastPage; i++) {
                TableCell cell = new TableCell();
                row.Cells.Add(cell);
                
                string pageString = (i).ToString(NumberFormatInfo.InvariantInfo);
                if (i == currentPage) {
                    Label label = new Label();

                    label.Text = pageString;
                    cell.Controls.Add(label);
                } else {
                    button = new DataControlPagerLinkButton(this);
                    
                    button.Text = pageString;
                    button.CommandName = DataControlCommands.PageCommandName;
                    button.CommandArgument = pageString;
                    ((DataControlPagerLinkButton)button).EnableCallback(BuildCallbackArgument(i - 1));
                    cell.Controls.Add(button);
                }
            }

            if (pages > lastPage) {
                TableCell cell = new TableCell();
                row.Cells.Add(cell);
                button = new DataControlPagerLinkButton(this);
                
                button.Text = "...";
                button.CommandName = DataControlCommands.PageCommandName;
                button.CommandArgument = (lastPage + 1).ToString(NumberFormatInfo.InvariantInfo);
                ((DataControlPagerLinkButton)button).EnableCallback(BuildCallbackArgument(lastPage));
                cell.Controls.Add(button);
            }

            bool isLastPageShown = lastPage == pages;
            if (addFirstLastPageButtons && currentPage != pages && !isLastPageShown) {
                string lastPageImageUrl = pagerSettings.LastPageImageUrl;
                TableCell cell = new TableCell();
                row.Cells.Add(cell);

                IButtonControl lastButton;
                if (lastPageImageUrl.Length > 0) {
                    lastButton = new DataControlImageButton(this);
                    ((DataControlImageButton)lastButton).ImageUrl = lastPageImageUrl;
                    ((DataControlImageButton)lastButton).AlternateText = HttpUtility.HtmlDecode(pagerSettings.LastPageText);
                    ((DataControlImageButton)lastButton).EnableCallback(BuildCallbackArgument(pagedDataSource.PageCount - 1));
                } else {
                    lastButton = new DataControlPagerLinkButton(this);
                    ((DataControlPagerLinkButton)lastButton).Text = pagerSettings.LastPageText;
                    ((DataControlPagerLinkButton)lastButton).EnableCallback(BuildCallbackArgument(pagedDataSource.PageCount - 1));
                }
                lastButton.CommandName = DataControlCommands.PageCommandName;
                lastButton.CommandArgument = DataControlCommands.LastPageCommandArgument;
                cell.Controls.Add((Control)lastButton);
            }
        }
 private void CreateNumericPager(TableRow row, PagedDataSource pagedDataSource, bool addFirstLastPageButtons)
 {
     LinkButton button;
     System.Web.UI.WebControls.PagerSettings pagerSettings = this.PagerSettings;
     int pageCount = pagedDataSource.PageCount;
     int num2 = pagedDataSource.CurrentPageIndex + 1;
     int pageButtonCount = pagerSettings.PageButtonCount;
     int num4 = pageButtonCount;
     int num5 = this.FirstDisplayedPageIndex + 1;
     if (pageCount < num4)
     {
         num4 = pageCount;
     }
     int num6 = 1;
     int pageIndex = num4;
     if (num2 > pageIndex)
     {
         int num8 = (num2 - 1) / pageButtonCount;
         bool flag = ((num2 - num5) >= 0) && ((num2 - num5) < pageButtonCount);
         if ((num5 > 0) && flag)
         {
             num6 = num5;
         }
         else
         {
             num6 = (num8 * pageButtonCount) + 1;
         }
         pageIndex = (num6 + pageButtonCount) - 1;
         if (pageIndex > pageCount)
         {
             pageIndex = pageCount;
         }
         if (((pageIndex - num6) + 1) < pageButtonCount)
         {
             num6 = Math.Max(1, (pageIndex - pageButtonCount) + 1);
         }
         this.FirstDisplayedPageIndex = num6 - 1;
     }
     if ((addFirstLastPageButtons && (num2 != 1)) && (num6 != 1))
     {
         IButtonControl control;
         string firstPageImageUrl = pagerSettings.FirstPageImageUrl;
         TableCell cell = new TableCell();
         row.Cells.Add(cell);
         if (firstPageImageUrl.Length > 0)
         {
             control = new DataControlImageButton(this);
             ((DataControlImageButton) control).ImageUrl = firstPageImageUrl;
             ((DataControlImageButton) control).AlternateText = HttpUtility.HtmlDecode(pagerSettings.FirstPageText);
             ((DataControlImageButton) control).EnableCallback(this.BuildCallbackArgument(0));
         }
         else
         {
             control = new DataControlPagerLinkButton(this);
             ((DataControlPagerLinkButton) control).Text = pagerSettings.FirstPageText;
             ((DataControlPagerLinkButton) control).EnableCallback(this.BuildCallbackArgument(0));
         }
         control.CommandName = "Page";
         control.CommandArgument = "First";
         cell.Controls.Add((Control) control);
     }
     if (num6 != 1)
     {
         TableCell cell2 = new TableCell();
         row.Cells.Add(cell2);
         button = new DataControlPagerLinkButton(this) {
             Text = "...",
             CommandName = "Page"
         };
         button.CommandArgument = (num6 - 1).ToString(NumberFormatInfo.InvariantInfo);
         ((DataControlPagerLinkButton) button).EnableCallback(this.BuildCallbackArgument(num6 - 2));
         cell2.Controls.Add(button);
     }
     for (int i = num6; i <= pageIndex; i++)
     {
         TableCell cell3 = new TableCell();
         row.Cells.Add(cell3);
         string str2 = i.ToString(NumberFormatInfo.InvariantInfo);
         if (i == num2)
         {
             Label child = new Label {
                 Text = str2
             };
             cell3.Controls.Add(child);
         }
         else
         {
             button = new DataControlPagerLinkButton(this) {
                 Text = str2,
                 CommandName = "Page",
                 CommandArgument = str2
             };
             ((DataControlPagerLinkButton) button).EnableCallback(this.BuildCallbackArgument(i - 1));
             cell3.Controls.Add(button);
         }
     }
     if (pageCount > pageIndex)
     {
         TableCell cell4 = new TableCell();
         row.Cells.Add(cell4);
         button = new DataControlPagerLinkButton(this) {
             Text = "...",
             CommandName = "Page"
         };
         button.CommandArgument = (pageIndex + 1).ToString(NumberFormatInfo.InvariantInfo);
         ((DataControlPagerLinkButton) button).EnableCallback(this.BuildCallbackArgument(pageIndex));
         cell4.Controls.Add(button);
     }
     bool flag2 = pageIndex == pageCount;
     if ((addFirstLastPageButtons && (num2 != pageCount)) && !flag2)
     {
         IButtonControl control2;
         string lastPageImageUrl = pagerSettings.LastPageImageUrl;
         TableCell cell5 = new TableCell();
         row.Cells.Add(cell5);
         if (lastPageImageUrl.Length > 0)
         {
             control2 = new DataControlImageButton(this);
             ((DataControlImageButton) control2).ImageUrl = lastPageImageUrl;
             ((DataControlImageButton) control2).AlternateText = HttpUtility.HtmlDecode(pagerSettings.LastPageText);
             ((DataControlImageButton) control2).EnableCallback(this.BuildCallbackArgument(pagedDataSource.PageCount - 1));
         }
         else
         {
             control2 = new DataControlPagerLinkButton(this);
             ((DataControlPagerLinkButton) control2).Text = pagerSettings.LastPageText;
             ((DataControlPagerLinkButton) control2).EnableCallback(this.BuildCallbackArgument(pagedDataSource.PageCount - 1));
         }
         control2.CommandName = "Page";
         control2.CommandArgument = "Last";
         cell5.Controls.Add((Control) control2);
     }
 }
Пример #3
0
        /// <devdoc>
        /// Creates the pager for NextPrev and NextPrev with First and Last styles
        /// </devdoc>
        private void CreateNextPrevPager(TableRow row, PagedDataSource pagedDataSource, bool addFirstLastPageButtons) {
            PagerSettings pagerSettings = PagerSettings;
            string prevPageImageUrl = pagerSettings.PreviousPageImageUrl;
            string nextPageImageUrl = pagerSettings.NextPageImageUrl;
            bool isFirstPage = pagedDataSource.IsFirstPage;
            bool isLastPage = pagedDataSource.IsLastPage;


            if (addFirstLastPageButtons && !isFirstPage) {
                string firstPageImageUrl = pagerSettings.FirstPageImageUrl;
                TableCell cell = new TableCell();
                row.Cells.Add(cell);
                IButtonControl firstButton;
                if (firstPageImageUrl.Length > 0) {
                    firstButton = new DataControlImageButton(this);
                    ((DataControlImageButton)firstButton).ImageUrl = firstPageImageUrl;
                    ((DataControlImageButton)firstButton).AlternateText = HttpUtility.HtmlDecode(pagerSettings.FirstPageText);
                    ((DataControlImageButton)firstButton).EnableCallback(BuildCallbackArgument(0));
                } else {
                    firstButton = new DataControlPagerLinkButton(this);
                    ((DataControlPagerLinkButton)firstButton).Text = pagerSettings.FirstPageText;
                    ((DataControlPagerLinkButton)firstButton).EnableCallback(BuildCallbackArgument(0));
                }
                firstButton.CommandName = DataControlCommands.PageCommandName;
                firstButton.CommandArgument = DataControlCommands.FirstPageCommandArgument;
                cell.Controls.Add((Control)firstButton);
            }

            if (!isFirstPage) {
                IButtonControl prevButton;
                TableCell cell = new TableCell();
                row.Cells.Add(cell);
                if (prevPageImageUrl.Length > 0) {
                    prevButton = new DataControlImageButton(this);
                    ((DataControlImageButton)prevButton).ImageUrl = prevPageImageUrl;
                    ((DataControlImageButton)prevButton).AlternateText = HttpUtility.HtmlDecode(pagerSettings.PreviousPageText);
                    ((DataControlImageButton)prevButton).EnableCallback(BuildCallbackArgument(PageIndex - 1));
                } else {
                    prevButton = new DataControlPagerLinkButton(this);
                    ((DataControlPagerLinkButton)prevButton).Text = pagerSettings.PreviousPageText;
                    ((DataControlPagerLinkButton)prevButton).EnableCallback(BuildCallbackArgument(PageIndex - 1));
                }
                prevButton.CommandName = DataControlCommands.PageCommandName;
                prevButton.CommandArgument = DataControlCommands.PreviousPageCommandArgument;
                cell.Controls.Add((Control)prevButton);
            }


            if (!isLastPage) {
                IButtonControl nextButton;
                TableCell cell = new TableCell();
                row.Cells.Add(cell);
                if (nextPageImageUrl.Length > 0) {
                    nextButton = new DataControlImageButton(this);
                    ((DataControlImageButton)nextButton).ImageUrl = nextPageImageUrl;
                    ((DataControlImageButton)nextButton).AlternateText = HttpUtility.HtmlDecode(pagerSettings.NextPageText);
                    ((DataControlImageButton)nextButton).EnableCallback(BuildCallbackArgument(PageIndex + 1));
                } else {
                    nextButton = new DataControlPagerLinkButton(this);
                    ((DataControlPagerLinkButton)nextButton).Text = pagerSettings.NextPageText;
                    ((DataControlPagerLinkButton)nextButton).EnableCallback(BuildCallbackArgument(PageIndex + 1));
                }
                nextButton.CommandName = DataControlCommands.PageCommandName;
                nextButton.CommandArgument = DataControlCommands.NextPageCommandArgument;
                cell.Controls.Add((Control)nextButton);
            }

            if (addFirstLastPageButtons && !isLastPage) {
                string lastPageImageUrl = pagerSettings.LastPageImageUrl;
                IButtonControl lastButton;
                TableCell cell = new TableCell();
                row.Cells.Add(cell);
                if (lastPageImageUrl.Length > 0) {
                    lastButton = new DataControlImageButton(this);
                    ((DataControlImageButton)lastButton).ImageUrl = lastPageImageUrl;
                    ((DataControlImageButton)lastButton).AlternateText = HttpUtility.HtmlDecode(pagerSettings.LastPageText);
                    ((DataControlImageButton)lastButton).EnableCallback(BuildCallbackArgument(pagedDataSource.PageCount - 1));
                } else {
                    lastButton = new DataControlPagerLinkButton(this);
                    ((DataControlPagerLinkButton)lastButton).Text = pagerSettings.LastPageText;
                    ((DataControlPagerLinkButton)lastButton).EnableCallback(BuildCallbackArgument(pagedDataSource.PageCount - 1));
                }
                lastButton.CommandName = DataControlCommands.PageCommandName;
                lastButton.CommandArgument = DataControlCommands.LastPageCommandArgument;
                cell.Controls.Add((Control)lastButton);
            }
        }
 private void CreateNextPrevPager(TableRow row, PagedDataSource pagedDataSource, bool addFirstLastPageButtons)
 {
     System.Web.UI.WebControls.PagerSettings pagerSettings = this.PagerSettings;
     string previousPageImageUrl = pagerSettings.PreviousPageImageUrl;
     string nextPageImageUrl = pagerSettings.NextPageImageUrl;
     bool isFirstPage = pagedDataSource.IsFirstPage;
     bool isLastPage = pagedDataSource.IsLastPage;
     if (addFirstLastPageButtons && !isFirstPage)
     {
         IButtonControl control;
         string firstPageImageUrl = pagerSettings.FirstPageImageUrl;
         TableCell cell = new TableCell();
         row.Cells.Add(cell);
         if (firstPageImageUrl.Length > 0)
         {
             control = new DataControlImageButton(this);
             ((DataControlImageButton) control).ImageUrl = firstPageImageUrl;
             ((DataControlImageButton) control).AlternateText = HttpUtility.HtmlDecode(pagerSettings.FirstPageText);
             ((DataControlImageButton) control).EnableCallback(this.BuildCallbackArgument(0));
         }
         else
         {
             control = new DataControlPagerLinkButton(this);
             ((DataControlPagerLinkButton) control).Text = pagerSettings.FirstPageText;
             ((DataControlPagerLinkButton) control).EnableCallback(this.BuildCallbackArgument(0));
         }
         control.CommandName = "Page";
         control.CommandArgument = "First";
         cell.Controls.Add((Control) control);
     }
     if (!isFirstPage)
     {
         IButtonControl control2;
         TableCell cell2 = new TableCell();
         row.Cells.Add(cell2);
         if (previousPageImageUrl.Length > 0)
         {
             control2 = new DataControlImageButton(this);
             ((DataControlImageButton) control2).ImageUrl = previousPageImageUrl;
             ((DataControlImageButton) control2).AlternateText = HttpUtility.HtmlDecode(pagerSettings.PreviousPageText);
             ((DataControlImageButton) control2).EnableCallback(this.BuildCallbackArgument(this.PageIndex - 1));
         }
         else
         {
             control2 = new DataControlPagerLinkButton(this);
             ((DataControlPagerLinkButton) control2).Text = pagerSettings.PreviousPageText;
             ((DataControlPagerLinkButton) control2).EnableCallback(this.BuildCallbackArgument(this.PageIndex - 1));
         }
         control2.CommandName = "Page";
         control2.CommandArgument = "Prev";
         cell2.Controls.Add((Control) control2);
     }
     if (!isLastPage)
     {
         IButtonControl control3;
         TableCell cell3 = new TableCell();
         row.Cells.Add(cell3);
         if (nextPageImageUrl.Length > 0)
         {
             control3 = new DataControlImageButton(this);
             ((DataControlImageButton) control3).ImageUrl = nextPageImageUrl;
             ((DataControlImageButton) control3).AlternateText = HttpUtility.HtmlDecode(pagerSettings.NextPageText);
             ((DataControlImageButton) control3).EnableCallback(this.BuildCallbackArgument(this.PageIndex + 1));
         }
         else
         {
             control3 = new DataControlPagerLinkButton(this);
             ((DataControlPagerLinkButton) control3).Text = pagerSettings.NextPageText;
             ((DataControlPagerLinkButton) control3).EnableCallback(this.BuildCallbackArgument(this.PageIndex + 1));
         }
         control3.CommandName = "Page";
         control3.CommandArgument = "Next";
         cell3.Controls.Add((Control) control3);
     }
     if (addFirstLastPageButtons && !isLastPage)
     {
         IButtonControl control4;
         string lastPageImageUrl = pagerSettings.LastPageImageUrl;
         TableCell cell4 = new TableCell();
         row.Cells.Add(cell4);
         if (lastPageImageUrl.Length > 0)
         {
             control4 = new DataControlImageButton(this);
             ((DataControlImageButton) control4).ImageUrl = lastPageImageUrl;
             ((DataControlImageButton) control4).AlternateText = HttpUtility.HtmlDecode(pagerSettings.LastPageText);
             ((DataControlImageButton) control4).EnableCallback(this.BuildCallbackArgument(pagedDataSource.PageCount - 1));
         }
         else
         {
             control4 = new DataControlPagerLinkButton(this);
             ((DataControlPagerLinkButton) control4).Text = pagerSettings.LastPageText;
             ((DataControlPagerLinkButton) control4).EnableCallback(this.BuildCallbackArgument(pagedDataSource.PageCount - 1));
         }
         control4.CommandName = "Page";
         control4.CommandArgument = "Last";
         cell4.Controls.Add((Control) control4);
     }
 }