public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) { base.InitializeCell(cell, columnIndex, itemType); if (Enum.IsDefined(typeof(ListItemType), itemType) && itemType != ListItemType.Footer && itemType != ListItemType.Header) { WebControl toDisplay = null; if(ButtonType == ButtonColumnType.PushButton) { Button b = new Button(); b.Text = Text; b.CommandName = CommandName; b.CausesValidation = false; toDisplay = b; } else { LinkButton lb = new DataGridLinkButton(); lb.Text = Text; lb.CommandName = CommandName; lb.CausesValidation = false; toDisplay = lb; } if(DataTextField.Length > 0) { toDisplay.DataBinding += new EventHandler(OnDataBindButtonColumn); } cell.Controls.Add(toDisplay); } }
public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) { base.InitializeCell(cell, columnIndex, itemType); if ((itemType != ListItemType.Header) && (itemType != ListItemType.Footer)) { WebControl child = null; if (this.ButtonType == ButtonColumnType.LinkButton) { LinkButton button = new DataGridLinkButton { Text = this.Text, CommandName = this.CommandName, CausesValidation = this.CausesValidation, ValidationGroup = this.ValidationGroup }; child = button; } else { Button button2 = new Button { Text = this.Text, CommandName = this.CommandName, CausesValidation = this.CausesValidation, ValidationGroup = this.ValidationGroup }; child = button2; } if (this.DataTextField.Length != 0) { child.DataBinding += new EventHandler(this.OnDataBindColumn); } cell.Controls.Add(child); } }
private void AddButtonToCell(TableCell cell, string commandName, string buttonText, bool causesValidation, string validationGroup) { WebControl child = null; ControlCollection controls = cell.Controls; if (this.ButtonType == ButtonColumnType.LinkButton) { LinkButton button = new DataGridLinkButton(); child = button; button.CommandName = commandName; button.Text = buttonText; button.CausesValidation = causesValidation; button.ValidationGroup = validationGroup; } else { Button button2 = new Button(); child = button2; button2.CommandName = commandName; button2.Text = buttonText; button2.CausesValidation = causesValidation; button2.ValidationGroup = validationGroup; } controls.Add(child); }
/// <devdoc> /// <para>Initializes a cell in the <see cref='System.Web.UI.WebControls.ButtonColumn'/> .</para> /// </devdoc> public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) { base.InitializeCell(cell, columnIndex, itemType); if ((itemType != ListItemType.Header) && (itemType != ListItemType.Footer)) { WebControl buttonControl = null; if (ButtonType == ButtonColumnType.LinkButton) { LinkButton button = new DataGridLinkButton(); button.Text = Text; button.CommandName = CommandName; button.CausesValidation = CausesValidation; button.ValidationGroup = ValidationGroup; buttonControl = button; } else { Button button = new Button(); button.Text = Text; button.CommandName = CommandName; button.CausesValidation = CausesValidation; button.ValidationGroup = ValidationGroup; buttonControl = button; } if (DataTextField.Length != 0) { buttonControl.DataBinding += new EventHandler(this.OnDataBindColumn); } cell.Controls.Add(buttonControl); } }
Control MakeButton (string commandName, string text) { if (ButtonType == ButtonColumnType.LinkButton) { DataGridLinkButton ret = new DataGridLinkButton (); ret.CommandName = commandName; ret.Text = text; return ret; } else { Button ret = new Button (); ret.CommandName = commandName; ret.Text = text; return ret; } }
/// <devdoc> /// <para> /// Creates a DataGridItem that contains the paging UI. /// The paging UI is a navigation bar that is a built into a single TableCell that /// spans across all columns of the DataGrid. /// </para> /// </devdoc> protected virtual void InitializePager(DataGridItem item, int columnSpan, PagedDataSource pagedDataSource) { TableCell cell = new TableCell(); if (columnSpan > 1) { cell.ColumnSpan = columnSpan; } DataGridPagerStyle pagerStyle = PagerStyle; if (pagerStyle.Mode == PagerMode.NextPrev) { if (pagedDataSource.IsFirstPage == false) { LinkButton prevButton = new DataGridLinkButton(); prevButton.Text = pagerStyle.PrevPageText; prevButton.CommandName = DataGrid.PageCommandName; prevButton.CommandArgument = DataGrid.PrevPageCommandArgument; prevButton.CausesValidation = false; cell.Controls.Add(prevButton); } else { Label prevLabel = new Label(); prevLabel.Text = pagerStyle.PrevPageText; cell.Controls.Add(prevLabel); } cell.Controls.Add(new LiteralControl(" ")); if (pagedDataSource.IsLastPage == false) { LinkButton nextButton = new DataGridLinkButton(); nextButton.Text = pagerStyle.NextPageText; nextButton.CommandName = DataGrid.PageCommandName; nextButton.CommandArgument = DataGrid.NextPageCommandArgument; nextButton.CausesValidation = false; cell.Controls.Add(nextButton); } else { Label nextLabel = new Label(); nextLabel.Text = pagerStyle.NextPageText; cell.Controls.Add(nextLabel); } } else { int pages = pagedDataSource.PageCount; int currentPage = pagedDataSource.CurrentPageIndex + 1; int pageSetSize = pagerStyle.PageButtonCount; int pagesShown = pageSetSize; // ensure the number of pages we show isn't more than the number of pages that do exist if (pages < pagesShown) pagesShown = pages; // initialze 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 = pagedDataSource.CurrentPageIndex / pageSetSize; 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); } } LinkButton button; if (firstPage != 1) { button = new DataGridLinkButton(); button.Text = "..."; button.CommandName = DataGrid.PageCommandName; button.CommandArgument = (firstPage - 1).ToString(NumberFormatInfo.InvariantInfo); button.CausesValidation = false; cell.Controls.Add(button); cell.Controls.Add(new LiteralControl(" ")); } for (int i = firstPage; i <= lastPage; i++) { string pageString = (i).ToString(NumberFormatInfo.InvariantInfo); if (i == currentPage) { Label label = new Label(); label.Text = pageString; cell.Controls.Add(label); } else { button = new DataGridLinkButton(); button.Text = pageString; button.CommandName = DataGrid.PageCommandName; button.CommandArgument = pageString; button.CausesValidation = false; cell.Controls.Add(button); } if (i < lastPage) { cell.Controls.Add(new LiteralControl(" ")); } } if (pages > lastPage) { cell.Controls.Add(new LiteralControl(" ")); button = new DataGridLinkButton(); button.Text = "..."; button.CommandName = DataGrid.PageCommandName; button.CommandArgument = (lastPage + 1).ToString(NumberFormatInfo.InvariantInfo); button.CausesValidation = false; cell.Controls.Add(button); } } item.Cells.Add(cell); }
/// <devdoc> /// <para>Initializes a cell in the System.Web.UI.WebControls.Column.</para> /// </devdoc> public virtual void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) { switch (itemType) { case ListItemType.Header: { WebControl headerControl = null; bool sortableHeader = true; string sortExpression = null; if ((owner != null) && (owner.AllowSorting == false)) { sortableHeader = false; } if (sortableHeader) { sortExpression = SortExpression; if (sortExpression.Length == 0) { sortableHeader = false; } } string headerImageUrl = HeaderImageUrl; if (headerImageUrl.Length != 0) { if (sortableHeader) { ImageButton sortButton = new ImageButton(); sortButton.ImageUrl = HeaderImageUrl; sortButton.CommandName = DataGrid.SortCommandName; sortButton.CommandArgument = sortExpression; sortButton.CausesValidation = false; headerControl = sortButton; } else { Image headerImage = new Image(); headerImage.ImageUrl = headerImageUrl; headerControl = headerImage; } } else { string headerText = HeaderText; if (sortableHeader) { LinkButton sortButton = new DataGridLinkButton(); sortButton.Text = headerText; sortButton.CommandName = DataGrid.SortCommandName; sortButton.CommandArgument = sortExpression; 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 = " "; } cell.Text = headerText; } } if (headerControl != null) { cell.Controls.Add(headerControl); } } break; case ListItemType.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 = " "; } cell.Text = footerText; } break; } }
public virtual void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) { WebControl control; switch (itemType) { case ListItemType.Header: { control = null; bool flag = true; string sortExpression = null; if ((this.owner != null) && !this.owner.AllowSorting) { flag = false; } if (flag) { sortExpression = this.SortExpression; if (sortExpression.Length == 0) { flag = false; } } string headerImageUrl = this.HeaderImageUrl; if (headerImageUrl.Length == 0) { string headerText = this.HeaderText; if (flag) { LinkButton button2 = new DataGridLinkButton { Text = headerText, CommandName = "Sort", CommandArgument = sortExpression, CausesValidation = false }; control = button2; } else { if (headerText.Length == 0) { headerText = " "; } cell.Text = headerText; } break; } if (flag) { ImageButton button = new ImageButton { ImageUrl = this.HeaderImageUrl, CommandName = "Sort", CommandArgument = sortExpression, CausesValidation = false }; control = button; } else { Image image = new Image { ImageUrl = headerImageUrl }; control = image; } break; } case ListItemType.Footer: { string footerText = this.FooterText; if (footerText.Length == 0) { footerText = " "; } cell.Text = footerText; return; } default: return; } if (control != null) { cell.Controls.Add(control); } }
protected virtual void InitializePager(DataGridItem item, int columnSpan, PagedDataSource pagedDataSource) { TableCell toAdd = new TableCell(); toAdd.ColumnSpan = columnSpan; if(PagerStyle.Mode == PagerMode.NextPrev) { if(!pagedDataSource.IsFirstPage) { LinkButton link = new DataGridLinkButton(); link.Text = PagerStyle.PrevPageText; link.CommandName = "Page"; link.CommandArgument = "Prev"; link.CausesValidation = false; toAdd.Controls.Add(link); } else { Label label = new Label(); label.Text = PagerStyle.PrevPageText; toAdd.Controls.Add(label); } toAdd.Controls.Add(new LiteralControl(" ")); if (pagedDataSource.PageCount == 0) { Label label = new Label(); label.Text = PagerStyle.NextPageText; toAdd.Controls.Add(label); } else { if(!pagedDataSource.IsLastPage) { LinkButton link = new DataGridLinkButton(); link.Text = PagerStyle.NextPageText; link.CommandName = "Page"; link.CommandArgument = "Next"; link.CausesValidation = false; toAdd.Controls.Add(link); } else { Label label = new Label(); label.Text = PagerStyle.NextPageText; toAdd.Controls.Add(label); } } } else { int pageCount = pagedDataSource.PageCount; int currPage = pagedDataSource.CurrentPageIndex + 1; int btnCount = PagerStyle.PageButtonCount; int numberOfPages = btnCount; if(numberOfPages > pageCount) numberOfPages = pageCount; int firstPageNumber = 1; // 10 int lastPageNumber = numberOfPages; // 11 if(currPage > lastPageNumber) { firstPageNumber = (pagedDataSource.CurrentPageIndex / btnCount) * btnCount + 1; lastPageNumber = firstPageNumber + btnCount - 1; if(lastPageNumber > pageCount) lastPageNumber = pageCount; if((lastPageNumber - firstPageNumber + 1) < btnCount) firstPageNumber = Math.Max(1, lastPageNumber - btnCount + 1); } if(firstPageNumber != 1) { LinkButton toAddBtn = new DataGridLinkButton(); toAddBtn.Text = "..."; toAddBtn.CommandName = "Page"; toAddBtn.CommandArgument = (firstPageNumber - 1).ToString(NumberFormatInfo.InvariantInfo); toAddBtn.CausesValidation = false; toAdd.Controls.Add(toAddBtn); toAdd.Controls.Add(new LiteralControl(" ")); } if (lastPageNumber == 0) { Label cPageLabel = new Label(); cPageLabel.Text = "1"; toAdd.Controls.Add(cPageLabel); } else { for(int i = firstPageNumber; i <= lastPageNumber; i++) { string argText = i.ToString(NumberFormatInfo.InvariantInfo); if(i == currPage) { Label cPageLabel = new Label(); cPageLabel.Text = argText; toAdd.Controls.Add(cPageLabel); } else { LinkButton indexButton = new DataGridLinkButton(); indexButton.Text = argText; indexButton.CommandName = "Page"; indexButton.CommandArgument = argText; indexButton.CausesValidation = false; toAdd.Controls.Add(indexButton); } if(i < lastPageNumber) toAdd.Controls.Add(new LiteralControl(" ")); } } if(pageCount > lastPageNumber) { toAdd.Controls.Add(new LiteralControl(" ")); LinkButton contLink = new DataGridLinkButton(); contLink.Text = "..."; contLink.CommandName = "Page"; contLink.CommandArgument = (lastPageNumber + 1).ToString(NumberFormatInfo.InvariantInfo); contLink.CausesValidation = false; toAdd.Controls.Add(contLink); } } item.Cells.Add(toAdd); }
/// <devdoc> /// <para>Initializes a cell in the System.Web.UI.WebControls.Column.</para> /// </devdoc> public virtual void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) { switch (itemType) { case ListItemType.Header: { WebControl headerControl = null; bool sortableHeader = true; string sortExpression = null; if ((owner != null) && (owner.AllowSorting == false)) { sortableHeader = false; } if (sortableHeader) { sortExpression = SortExpression; if (sortExpression.Length == 0) sortableHeader = false; } string headerImageUrl = HeaderImageUrl; if (headerImageUrl.Length != 0) { if (sortableHeader) { ImageButton sortButton = new ImageButton(); sortButton.ImageUrl = HeaderImageUrl; sortButton.CommandName = DataGrid.SortCommandName; sortButton.CommandArgument = sortExpression; sortButton.CausesValidation = false; headerControl = sortButton; } else { Image headerImage = new Image(); headerImage.ImageUrl = headerImageUrl; headerControl = headerImage; } } else { string headerText = HeaderText; if (sortableHeader) { LinkButton sortButton = new DataGridLinkButton(); sortButton.Text = headerText; sortButton.CommandName = DataGrid.SortCommandName; sortButton.CommandArgument = sortExpression; 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 = " "; } cell.Text = headerText; } } if (headerControl != null) { cell.Controls.Add(headerControl); } } break; case ListItemType.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 = " "; } cell.Text = footerText; } break; } }
protected virtual void InitializePager(DataGridItem item, int columnSpan, PagedDataSource pagedDataSource) { TableCell cell = new TableCell(); if (columnSpan > 1) { cell.ColumnSpan = columnSpan; } DataGridPagerStyle pagerStyle = this.PagerStyle; if (pagerStyle.Mode == PagerMode.NextPrev) { if (!pagedDataSource.IsFirstPage) { LinkButton child = new DataGridLinkButton { Text = pagerStyle.PrevPageText, CommandName = "Page", CommandArgument = "Prev", CausesValidation = false }; cell.Controls.Add(child); } else { Label label = new Label { Text = pagerStyle.PrevPageText }; cell.Controls.Add(label); } cell.Controls.Add(new LiteralControl(" ")); if (!pagedDataSource.IsLastPage) { LinkButton button2 = new DataGridLinkButton { Text = pagerStyle.NextPageText, CommandName = "Page", CommandArgument = "Next", CausesValidation = false }; cell.Controls.Add(button2); } else { Label label2 = new Label { Text = pagerStyle.NextPageText }; cell.Controls.Add(label2); } } else { LinkButton button3; int pageCount = pagedDataSource.PageCount; int num2 = pagedDataSource.CurrentPageIndex + 1; int pageButtonCount = pagerStyle.PageButtonCount; int num4 = pageButtonCount; if (pageCount < num4) { num4 = pageCount; } int num5 = 1; int num6 = num4; if (num2 > num6) { int num7 = pagedDataSource.CurrentPageIndex / pageButtonCount; num5 = (num7 * pageButtonCount) + 1; num6 = (num5 + pageButtonCount) - 1; if (num6 > pageCount) { num6 = pageCount; } if (((num6 - num5) + 1) < pageButtonCount) { num5 = Math.Max(1, (num6 - pageButtonCount) + 1); } } if (num5 != 1) { button3 = new DataGridLinkButton { Text = "...", CommandName = "Page" }; button3.CommandArgument = (num5 - 1).ToString(NumberFormatInfo.InvariantInfo); button3.CausesValidation = false; cell.Controls.Add(button3); cell.Controls.Add(new LiteralControl(" ")); } for (int i = num5; i <= num6; i++) { string str = i.ToString(NumberFormatInfo.InvariantInfo); if (i == num2) { Label label3 = new Label { Text = str }; cell.Controls.Add(label3); } else { button3 = new DataGridLinkButton { Text = str, CommandName = "Page", CommandArgument = str, CausesValidation = false }; cell.Controls.Add(button3); } if (i < num6) { cell.Controls.Add(new LiteralControl(" ")); } } if (pageCount > num6) { cell.Controls.Add(new LiteralControl(" ")); button3 = new DataGridLinkButton { Text = "...", CommandName = "Page" }; button3.CommandArgument = (num6 + 1).ToString(NumberFormatInfo.InvariantInfo); button3.CausesValidation = false; cell.Controls.Add(button3); } } item.Cells.Add(cell); }
/// <include file='doc\EditCommandColumn.uex' path='docs/doc[@for="EditCommandColumn.InitializeCell"]/*' /> /// <devdoc> /// <para>Initializes a cell within the column.</para> /// </devdoc> public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) { base.InitializeCell(cell, columnIndex, itemType); if ((itemType != ListItemType.Header) && (itemType != ListItemType.Footer)) { if (itemType == ListItemType.EditItem) { ControlCollection controls = cell.Controls; ButtonColumnType buttonType = ButtonType; WebControl buttonControl = null; if (buttonType == ButtonColumnType.LinkButton) { LinkButton button = new DataGridLinkButton(); buttonControl = button; button.CommandName = DataGrid.UpdateCommandName; button.Text = UpdateText; } else { Button button = new Button(); buttonControl = button; button.CommandName = DataGrid.UpdateCommandName; button.Text = UpdateText; } controls.Add(buttonControl); LiteralControl spaceControl = new LiteralControl(" "); controls.Add(spaceControl); if (buttonType == ButtonColumnType.LinkButton) { LinkButton button = new DataGridLinkButton(); buttonControl = button; button.CommandName = DataGrid.CancelCommandName; button.Text = CancelText; button.CausesValidation = false; } else { Button button = new Button(); buttonControl = button; button.CommandName = DataGrid.CancelCommandName; button.Text = CancelText; button.CausesValidation = false; } controls.Add(buttonControl); } else { ControlCollection controls = cell.Controls; ButtonColumnType buttonType = ButtonType; WebControl buttonControl = null; if (buttonType == ButtonColumnType.LinkButton) { LinkButton button = new DataGridLinkButton(); buttonControl = button; button.CommandName = DataGrid.EditCommandName; button.Text = EditText; button.CausesValidation = false; } else { Button button = new Button(); buttonControl = button; button.CommandName = DataGrid.EditCommandName; button.Text = EditText; button.CausesValidation = false; } controls.Add(buttonControl); } } }