Exemple #1
0
        public static IDataControlButton CreateButton(ButtonType type, Control container, string text, string image, string command, string commandArg, bool allowCallback)
        {
            IDataControlButton btn;

            switch (type)
            {
            case ButtonType.Link:
                btn = new DataControlLinkButton();
                break;

            case ButtonType.Image:
                btn          = new DataControlImageButton();
                btn.ImageUrl = image;
                break;

            default:
                btn = new DataControlButton();
                break;
            }

            btn.Container        = container;
            btn.CommandName      = command;
            btn.CommandArgument  = commandArg;
            btn.Text             = text;
            btn.CausesValidation = false;
            btn.AllowCallback    = allowCallback;

            return(btn);
        }
		public static IDataControlButton CreateButton (ButtonType type, Control container, string text, string image, string command, string commandArg, bool allowCallback)
		{
			IDataControlButton btn;

			switch (type) {
			case ButtonType.Link:
				btn = new DataControlLinkButton ();
				break;
			case ButtonType.Image:
				btn = new DataControlImageButton ();
				btn.ImageUrl = image;
				break;
			default:
				btn = new DataControlButton ();
				break;
			}

			btn.Container = container;
			btn.CommandName = command;
			btn.CommandArgument = commandArg;
			btn.Text = text;
			btn.CausesValidation = false;
			btn.AllowCallback = allowCallback;

			return btn;
		}
        private void AddButtonToCell(DataControlFieldCell cell, string commandName, string buttonText, bool causesValidation, string validationGroup, int rowIndex, string imageUrl)
        {
            IButtonControl     control;
            IPostBackContainer container = base.Control as IPostBackContainer;
            bool flag = true;

            switch (this.ButtonType)
            {
            case ButtonType.Button:
                if ((container == null) || causesValidation)
                {
                    control = new Button();
                }
                else
                {
                    control = new DataControlButton(container);
                    flag    = false;
                }
                break;

            case ButtonType.Link:
                if ((container == null) || causesValidation)
                {
                    control = new DataControlLinkButton(null);
                }
                else
                {
                    control = new DataControlLinkButton(container);
                    flag    = false;
                }
                break;

            default:
                if ((container != null) && !causesValidation)
                {
                    control = new DataControlImageButton(container);
                    flag    = false;
                }
                else
                {
                    control = new ImageButton();
                }
                ((ImageButton)control).ImageUrl = imageUrl;
                break;
            }
            control.Text            = buttonText;
            control.CommandName     = commandName;
            control.CommandArgument = rowIndex.ToString(CultureInfo.InvariantCulture);
            if (flag)
            {
                control.CausesValidation = causesValidation;
            }
            control.ValidationGroup = validationGroup;
            cell.Controls.Add((WebControl)control);
        }
        private void AddButtonToCell(DataControlFieldCell cell, string commandName, string buttonText, bool causesValidation, string validationGroup, int rowIndex, string imageUrl)
        {
            IButtonControl control;
            IPostBackContainer container = base.Control as IPostBackContainer;
            bool flag = true;
            switch (this.ButtonType)
            {
                case ButtonType.Button:
                    if ((container == null) || causesValidation)
                    {
                        control = new Button();
                    }
                    else
                    {
                        control = new DataControlButton(container);
                        flag = false;
                    }
                    break;

                case ButtonType.Link:
                    if ((container == null) || causesValidation)
                    {
                        control = new DataControlLinkButton(null);
                    }
                    else
                    {
                        control = new DataControlLinkButton(container);
                        flag = false;
                    }
                    break;

                default:
                    if ((container != null) && !causesValidation)
                    {
                        control = new DataControlImageButton(container);
                        flag = false;
                    }
                    else
                    {
                        control = new ImageButton();
                    }
                    ((ImageButton) control).ImageUrl = imageUrl;
                    break;
            }
            control.Text = buttonText;
            control.CommandName = commandName;
            control.CommandArgument = rowIndex.ToString(CultureInfo.InvariantCulture);
            if (flag)
            {
                control.CausesValidation = causesValidation;
            }
            control.ValidationGroup = validationGroup;
            cell.Controls.Add((WebControl) control);
        }
Exemple #5
0
        public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
        {
            base.InitializeCell(cell, cellType, rowState, rowIndex);
            if ((cellType != DataControlCellType.Header) && (cellType != DataControlCellType.Footer))
            {
                IButtonControl     control;
                IPostBackContainer container = base.Control as IPostBackContainer;
                bool causesValidation        = this.CausesValidation;
                bool flag2 = true;
                switch (this.ButtonType)
                {
                case ButtonType.Button:
                    if ((container == null) || causesValidation)
                    {
                        control = new Button();
                    }
                    else
                    {
                        control = new DataControlButton(container);
                        flag2   = false;
                    }
                    break;

                case ButtonType.Link:
                    if ((container == null) || causesValidation)
                    {
                        control = new DataControlLinkButton(null);
                    }
                    else
                    {
                        control = new DataControlLinkButton(container);
                        flag2   = false;
                    }
                    break;

                default:
                    if ((container != null) && !causesValidation)
                    {
                        control = new DataControlImageButton(container);
                        flag2   = false;
                    }
                    else
                    {
                        control = new ImageButton();
                    }
                    ((ImageButton)control).ImageUrl = this.ImageUrl;
                    break;
                }
                control.Text            = this.Text;
                control.CommandName     = this.CommandName;
                control.CommandArgument = rowIndex.ToString(CultureInfo.InvariantCulture);
                if (flag2)
                {
                    control.CausesValidation = causesValidation;
                }
                control.ValidationGroup = this.ValidationGroup;
                if ((this.DataTextField.Length != 0) && base.Visible)
                {
                    ((WebControl)control).DataBinding += new EventHandler(this.OnDataBindField);
                }
                cell.Controls.Add((WebControl)control);
            }
        }
Exemple #6
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);
            }
        }
Exemple #7
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);
            }
        }
Exemple #8
0
        private void AddButtonToCell(DataControlFieldCell cell, string commandName, string buttonText, bool causesValidation, string validationGroup, int rowIndex, string imageUrl)
        {
            IButtonControl     button;
            IPostBackContainer container = Control as IPostBackContainer;
            bool setCausesValidation     = true; // the setter on the DataControlButtons throw if there's a container for security

            switch (ButtonType)
            {
            case ButtonType.Link: {
                if (container != null && !causesValidation)
                {
                    button = new DataControlLinkButton(container);
                    setCausesValidation = false;
                }
                else
                {
                    button = new DataControlLinkButton(null);
                }

                break;
            }

            case ButtonType.Button: {
                if (container != null && !causesValidation)
                {
                    button = new DataControlButton(container);
                    setCausesValidation = false;
                }
                else
                {
                    button = new Button();
                }

                break;
            }

            case ButtonType.Image:
            default: {
                if (container != null && !causesValidation)
                {
                    button = new DataControlImageButton(container);
                    setCausesValidation = false;
                }
                else
                {
                    button = new ImageButton();
                }

                ((ImageButton)button).ImageUrl = imageUrl;
                break;
            }
            }

            button.Text            = buttonText;
            button.CommandName     = commandName;
            button.CommandArgument = rowIndex.ToString(CultureInfo.InvariantCulture);
            if (setCausesValidation)
            {
                button.CausesValidation = causesValidation;
            }
            button.ValidationGroup = validationGroup;

            cell.Controls.Add((WebControl)button);
        }
        /// <devdoc>
        /// <para>Initializes a cell in the System.Web.UI.WebControls.Field.</para>
        /// </devdoc>
        public virtual void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex) {
            switch (cellType) {
                case DataControlCellType.Header:
                    {
                        WebControl headerControl = null;
                        string sortExpression = SortExpression;
                        bool sortableHeader = (_sortingEnabled && sortExpression.Length > 0);

                        string headerImageUrl = HeaderImageUrl;
                        string headerText = HeaderText;
                        if (headerImageUrl.Length != 0) {
                            if (sortableHeader) {
                                ImageButton sortButton;
                                IPostBackContainer container = _control as IPostBackContainer;
                                if (container != null) {
                                    sortButton = new DataControlImageButton(container);
                                    ((DataControlImageButton)sortButton).EnableCallback(null);  // no command argument for the callback uses Sort
                                }
                                else {
                                    sortButton = new ImageButton();
                                }

                                sortButton.ImageUrl = HeaderImageUrl;
                                sortButton.CommandName = DataControlCommands.SortCommandName;
                                sortButton.CommandArgument = sortExpression;
                                if (!(sortButton is DataControlImageButton)) {
                                    sortButton.CausesValidation = false;
                                }
                                sortButton.AlternateText = headerText;
                                headerControl = sortButton;
                            }
                            else {
                                Image headerImage = new Image();

                                headerImage.ImageUrl = headerImageUrl;
                                headerControl = headerImage;
                                headerImage.AlternateText = headerText;
                            }
                        }
                        else {
                            if (sortableHeader) {
                                LinkButton sortButton;
                                IPostBackContainer container = _control as IPostBackContainer;
                                if (container != null) {
                                    sortButton = new DataControlLinkButton(container);
                                    ((DataControlLinkButton)sortButton).EnableCallback(null);   // no command argument for the callback uses Sort
                                }
                                else {
                                    sortButton = new LinkButton();
                                }

                                sortButton.Text = headerText;
                                sortButton.CommandName = DataControlCommands.SortCommandName;
                                sortButton.CommandArgument = sortExpression;
                                if (!(sortButton is DataControlLinkButton)) {
                                    sortButton.CausesValidation = false;
                                }
                                headerControl = sortButton;
                            }
                            else {
                                if (headerText.Length == 0) {
                                    // the browser does not render table borders for cells with nothing
                                    // in their content, so we add a non-breaking space.
                                    headerText = "&nbsp;";
                                }
                                cell.Text = headerText;
                            }
                        }

                        if (headerControl != null) {
                            cell.Controls.Add(headerControl);
                        }
                    }
                    break;

                case DataControlCellType.Footer:
                    {
                        string footerText = FooterText;
                        if (footerText.Length == 0) {
                            // the browser does not render table borders for cells with nothing
                            // in their content, so we add a non-breaking space.
                            footerText = "&nbsp;";
                        }

                        cell.Text = footerText;
                    }
                    break;
            }
        }
 public virtual void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
 {
     WebControl control;
     string sortExpression;
     string headerText;
     ImageButton button;
     switch (cellType)
     {
         case DataControlCellType.Header:
         {
             control = null;
             sortExpression = this.SortExpression;
             bool flag = this._sortingEnabled && (sortExpression.Length > 0);
             string headerImageUrl = this.HeaderImageUrl;
             headerText = this.HeaderText;
             if (headerImageUrl.Length == 0)
             {
                 if (flag)
                 {
                     LinkButton button2;
                     IPostBackContainer container2 = this._control as IPostBackContainer;
                     if (container2 != null)
                     {
                         button2 = new DataControlLinkButton(container2);
                         ((DataControlLinkButton) button2).EnableCallback(null);
                     }
                     else
                     {
                         button2 = new LinkButton();
                     }
                     button2.Text = headerText;
                     button2.CommandName = "Sort";
                     button2.CommandArgument = sortExpression;
                     if (!(button2 is DataControlLinkButton))
                     {
                         button2.CausesValidation = false;
                     }
                     control = button2;
                 }
                 else
                 {
                     if (headerText.Length == 0)
                     {
                         headerText = "&nbsp;";
                     }
                     cell.Text = headerText;
                 }
                 goto Label_015C;
             }
             if (!flag)
             {
                 Image image = new Image {
                     ImageUrl = headerImageUrl
                 };
                 control = image;
                 image.AlternateText = headerText;
                 goto Label_015C;
             }
             IPostBackContainer container = this._control as IPostBackContainer;
             if (container == null)
             {
                 button = new ImageButton();
                 break;
             }
             button = new DataControlImageButton(container);
             ((DataControlImageButton) button).EnableCallback(null);
             break;
         }
         case DataControlCellType.Footer:
         {
             string footerText = this.FooterText;
             if (footerText.Length == 0)
             {
                 footerText = "&nbsp;";
             }
             cell.Text = footerText;
             return;
         }
         default:
             return;
     }
     button.ImageUrl = this.HeaderImageUrl;
     button.CommandName = "Sort";
     button.CommandArgument = sortExpression;
     if (!(button is DataControlImageButton))
     {
         button.CausesValidation = false;
     }
     button.AlternateText = headerText;
     control = button;
 Label_015C:
     if (control != null)
     {
         cell.Controls.Add(control);
     }
 }
        public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
        {
            base.InitializeCell(cell, cellType, rowState, rowIndex);
            if ((cellType != DataControlCellType.Header) && (cellType != DataControlCellType.Footer))
            {
                IButtonControl control;
                IPostBackContainer container = base.Control as IPostBackContainer;
                bool causesValidation = this.CausesValidation;
                bool flag2 = true;
                switch (this.ButtonType)
                {
                    case ButtonType.Button:
                        if ((container == null) || causesValidation)
                        {
                            control = new Button();
                        }
                        else
                        {
                            control = new DataControlButton(container);
                            flag2 = false;
                        }
                        break;

                    case ButtonType.Link:
                        if ((container == null) || causesValidation)
                        {
                            control = new DataControlLinkButton(null);
                        }
                        else
                        {
                            control = new DataControlLinkButton(container);
                            flag2 = false;
                        }
                        break;

                    default:
                        if ((container != null) && !causesValidation)
                        {
                            control = new DataControlImageButton(container);
                            flag2 = false;
                        }
                        else
                        {
                            control = new ImageButton();
                        }
                        ((ImageButton) control).ImageUrl = this.ImageUrl;
                        break;
                }
                control.Text = this.Text;
                control.CommandName = this.CommandName;
                control.CommandArgument = rowIndex.ToString(CultureInfo.InvariantCulture);
                if (flag2)
                {
                    control.CausesValidation = causesValidation;
                }
                control.ValidationGroup = this.ValidationGroup;
                if ((this.DataTextField.Length != 0) && base.Visible)
                {
                    ((WebControl) control).DataBinding += new EventHandler(this.OnDataBindField);
                }
                cell.Controls.Add((WebControl) control);
            }
        }
        public virtual void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
        {
            WebControl  control;
            string      sortExpression;
            string      headerText;
            ImageButton button;

            switch (cellType)
            {
            case DataControlCellType.Header:
            {
                control        = null;
                sortExpression = this.SortExpression;
                bool   flag           = this._sortingEnabled && (sortExpression.Length > 0);
                string headerImageUrl = this.HeaderImageUrl;
                headerText = this.HeaderText;
                if (headerImageUrl.Length == 0)
                {
                    if (flag)
                    {
                        LinkButton         button2;
                        IPostBackContainer container2 = this._control as IPostBackContainer;
                        if (container2 != null)
                        {
                            button2 = new DataControlLinkButton(container2);
                            ((DataControlLinkButton)button2).EnableCallback(null);
                        }
                        else
                        {
                            button2 = new LinkButton();
                        }
                        button2.Text            = headerText;
                        button2.CommandName     = "Sort";
                        button2.CommandArgument = sortExpression;
                        if (!(button2 is DataControlLinkButton))
                        {
                            button2.CausesValidation = false;
                        }
                        control = button2;
                    }
                    else
                    {
                        if (headerText.Length == 0)
                        {
                            headerText = "&nbsp;";
                        }
                        cell.Text = headerText;
                    }
                    goto Label_015C;
                }
                if (!flag)
                {
                    Image image = new Image {
                        ImageUrl = headerImageUrl
                    };
                    control             = image;
                    image.AlternateText = headerText;
                    goto Label_015C;
                }
                IPostBackContainer container = this._control as IPostBackContainer;
                if (container == null)
                {
                    button = new ImageButton();
                    break;
                }
                button = new DataControlImageButton(container);
                ((DataControlImageButton)button).EnableCallback(null);
                break;
            }

            case DataControlCellType.Footer:
            {
                string footerText = this.FooterText;
                if (footerText.Length == 0)
                {
                    footerText = "&nbsp;";
                }
                cell.Text = footerText;
                return;
            }

            default:
                return;
            }
            button.ImageUrl        = this.HeaderImageUrl;
            button.CommandName     = "Sort";
            button.CommandArgument = sortExpression;
            if (!(button is DataControlImageButton))
            {
                button.CausesValidation = false;
            }
            button.AlternateText = headerText;
            control = button;
Label_015C:
            if (control != null)
            {
                cell.Controls.Add(control);
            }
        }
 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);
     }
 }
 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);
     }
 }
        /// <devdoc>
        /// <para>Initializes a cell in the System.Web.UI.WebControls.Field.</para>
        /// </devdoc>
        public virtual void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
        {
            switch (cellType)
            {
            case DataControlCellType.Header:
            {
                WebControl headerControl  = null;
                string     sortExpression = SortExpression;
                bool       sortableHeader = (_sortingEnabled && sortExpression.Length > 0);

                string headerImageUrl = HeaderImageUrl;
                string headerText     = HeaderText;
                if (headerImageUrl.Length != 0)
                {
                    if (sortableHeader)
                    {
                        ImageButton        sortButton;
                        IPostBackContainer container = _control as IPostBackContainer;
                        if (container != null)
                        {
                            sortButton = new DataControlImageButton(container);
                            ((DataControlImageButton)sortButton).EnableCallback(null);          // no command argument for the callback uses Sort
                        }
                        else
                        {
                            sortButton = new ImageButton();
                        }

                        sortButton.ImageUrl        = HeaderImageUrl;
                        sortButton.CommandName     = DataControlCommands.SortCommandName;
                        sortButton.CommandArgument = sortExpression;
                        if (!(sortButton is DataControlImageButton))
                        {
                            sortButton.CausesValidation = false;
                        }
                        sortButton.AlternateText = headerText;
                        headerControl            = sortButton;
                    }
                    else
                    {
                        Image headerImage = new Image();

                        headerImage.ImageUrl      = headerImageUrl;
                        headerControl             = headerImage;
                        headerImage.AlternateText = headerText;
                    }
                }
                else
                {
                    if (sortableHeader)
                    {
                        LinkButton         sortButton;
                        IPostBackContainer container = _control as IPostBackContainer;
                        if (container != null)
                        {
                            sortButton = new DataControlLinkButton(container);
                            ((DataControlLinkButton)sortButton).EnableCallback(null);           // no command argument for the callback uses Sort
                        }
                        else
                        {
                            sortButton = new LinkButton();
                        }

                        sortButton.Text            = headerText;
                        sortButton.CommandName     = DataControlCommands.SortCommandName;
                        sortButton.CommandArgument = sortExpression;
                        if (!(sortButton is DataControlLinkButton))
                        {
                            sortButton.CausesValidation = false;
                        }
                        headerControl = sortButton;
                    }
                    else
                    {
                        if (headerText.Length == 0)
                        {
                            // the browser does not render table borders for cells with nothing
                            // in their content, so we add a non-breaking space.
                            headerText = "&nbsp;";
                        }
                        cell.Text = headerText;
                    }
                }

                if (headerControl != null)
                {
                    cell.Controls.Add(headerControl);
                }
            }
            break;

            case DataControlCellType.Footer:
            {
                string footerText = FooterText;
                if (footerText.Length == 0)
                {
                    // the browser does not render table borders for cells with nothing
                    // in their content, so we add a non-breaking space.
                    footerText = "&nbsp;";
                }

                cell.Text = footerText;
            }
            break;
            }
        }
        private void AddButtonToCell(DataControlFieldCell cell,  string commandName, string buttonText, bool causesValidation, string validationGroup, int rowIndex, string imageUrl) {
            IButtonControl button;
            IPostBackContainer container = Control as IPostBackContainer;
            bool setCausesValidation = true;    // the setter on the DataControlButtons throw if there's a container for security

            switch (ButtonType) {
                case ButtonType.Link: {
                    if (container != null && !causesValidation) {
                        button = new DataControlLinkButton(container);
                        setCausesValidation = false;
                    }
                    else {
                        button = new DataControlLinkButton(null);
                    }

                    break;
                }
                case ButtonType.Button: {
                    if (container != null && !causesValidation) {
                        button = new DataControlButton(container);
                        setCausesValidation = false;
                    }
                    else {
                        button = new Button();
                    }

                    break;
                }
                case ButtonType.Image:
                default: {
                    if (container != null && !causesValidation) {
                        button = new DataControlImageButton(container);
                        setCausesValidation = false;
                    }
                    else {
                        button = new ImageButton();
                    }

                    ((ImageButton)button).ImageUrl = imageUrl;
                    break;
                }
            }
            
            button.Text = buttonText;
            button.CommandName = commandName;
            button.CommandArgument = rowIndex.ToString(CultureInfo.InvariantCulture);
            if (setCausesValidation) {
                button.CausesValidation = causesValidation;
            }
            button.ValidationGroup = validationGroup;

            cell.Controls.Add((WebControl)button);

        }
        /// <devdoc>
        /// <para>Initializes a cell in the <see cref='System.Web.UI.WebControls.ButtonField'/> .</para>
        /// </devdoc>
        public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex) {
            base.InitializeCell(cell, cellType, rowState, rowIndex);

            if ((cellType != DataControlCellType.Header) &&
                (cellType != DataControlCellType.Footer)) {
                IButtonControl button;
                IPostBackContainer container = Control as IPostBackContainer;
                bool causesValidation = CausesValidation;
                bool setCausesValidation = true;    // the setter on the DataControlButtons throw if there's a container for security

                switch(ButtonType) {
                    case ButtonType.Link: {
                        if (container != null && !causesValidation) {
                            button = new DataControlLinkButton(container);
                            setCausesValidation = false;
                        }
                        else {
                            // use DataControlLinkButton because it uses the right forecolor
                            button = new DataControlLinkButton(null);
                        }
                        break;
                    }
                    case ButtonType.Button: {
                        if (container != null && !causesValidation) {
                            button = new DataControlButton(container);
                            setCausesValidation = false;
                        }
                        else {
                            button = new Button();
                        }
                        break;
                    }
                    case ButtonType.Image:
                    default: {
                        if (container != null && !causesValidation) {
                            button = new DataControlImageButton(container);
                            setCausesValidation = false;
                        }
                        else {
                            button = new ImageButton();
                        }

                        ((ImageButton)button).ImageUrl = ImageUrl;
                        break;
                    }
                }

                button.Text = Text;
                button.CommandName = CommandName;
                button.CommandArgument = rowIndex.ToString(CultureInfo.InvariantCulture);
                if (setCausesValidation) {
                    button.CausesValidation = causesValidation;
                }
                button.ValidationGroup = ValidationGroup;
                
                if (DataTextField.Length != 0 && Visible) {
                    ((WebControl)button).DataBinding += new EventHandler(this.OnDataBindField);
                }

                cell.Controls.Add((WebControl)button);
            }
        }
Exemple #18
0
        /// <devdoc>
        /// <para>Initializes a cell in the <see cref='System.Web.UI.WebControls.ButtonField'/> .</para>
        /// </devdoc>
        public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
        {
            base.InitializeCell(cell, cellType, rowState, rowIndex);

            if ((cellType != DataControlCellType.Header) &&
                (cellType != DataControlCellType.Footer))
            {
                IButtonControl     button;
                IPostBackContainer container = Control as IPostBackContainer;
                bool causesValidation        = CausesValidation;
                bool setCausesValidation     = true; // the setter on the DataControlButtons throw if there's a container for security

                switch (ButtonType)
                {
                case ButtonType.Link: {
                    if (container != null && !causesValidation)
                    {
                        button = new DataControlLinkButton(container);
                        setCausesValidation = false;
                    }
                    else
                    {
                        // use DataControlLinkButton because it uses the right forecolor
                        button = new DataControlLinkButton(null);
                    }
                    break;
                }

                case ButtonType.Button: {
                    if (container != null && !causesValidation)
                    {
                        button = new DataControlButton(container);
                        setCausesValidation = false;
                    }
                    else
                    {
                        button = new Button();
                    }
                    break;
                }

                case ButtonType.Image:
                default: {
                    if (container != null && !causesValidation)
                    {
                        button = new DataControlImageButton(container);
                        setCausesValidation = false;
                    }
                    else
                    {
                        button = new ImageButton();
                    }

                    ((ImageButton)button).ImageUrl = ImageUrl;
                    break;
                }
                }

                button.Text            = Text;
                button.CommandName     = CommandName;
                button.CommandArgument = rowIndex.ToString(CultureInfo.InvariantCulture);
                if (setCausesValidation)
                {
                    button.CausesValidation = causesValidation;
                }
                button.ValidationGroup = ValidationGroup;

                if (DataTextField.Length != 0 && Visible)
                {
                    ((WebControl)button).DataBinding += new EventHandler(this.OnDataBindField);
                }

                cell.Controls.Add((WebControl)button);
            }
        }