private void WritePagerSection(HtmlTextWriter writer, PagerPosition pos) { GridView gridView = Control as GridView; if ((gridView != null) && gridView.AllowPaging && ((gridView.PagerSettings.Position == pos) || (gridView.PagerSettings.Position == PagerPosition.TopAndBottom))) { Table innerTable = null; if ((pos == PagerPosition.Top) && (gridView.TopPagerRow != null) && (gridView.TopPagerRow.Cells.Count == 1) && (gridView.TopPagerRow.Cells[0].Controls.Count == 1) && typeof(Table).IsAssignableFrom(gridView.TopPagerRow.Cells[0].Controls[0].GetType())) { innerTable = gridView.TopPagerRow.Cells[0].Controls[0] as Table; } else if ((pos == PagerPosition.Bottom) && (gridView.BottomPagerRow != null) && (gridView.BottomPagerRow.Cells.Count == 1) && (gridView.BottomPagerRow.Cells[0].Controls.Count == 1) && typeof(Table).IsAssignableFrom(gridView.BottomPagerRow.Cells[0].Controls[0].GetType())) { innerTable = gridView.BottomPagerRow.Cells[0].Controls[0] as Table; } if ((innerTable != null) && (innerTable.Rows.Count == 1)) { string className = "AspNet-GridView-Pagination AspNet-GridView-"; className += (pos == PagerPosition.Top) ? "Top " : "Bottom "; if (gridView.PagerStyle != null) { className += gridView.PagerStyle.CssClass; } className = className.Trim(); writer.WriteLine(); writer.WriteBeginTag("div"); writer.WriteAttribute("class", className); writer.Write(HtmlTextWriter.TagRightChar); writer.Indent++; TableRow row = innerTable.Rows[0]; foreach (TableCell cell in row.Cells) { foreach (Control ctrl in cell.Controls) { writer.WriteLine(); ctrl.RenderControl(writer); } } writer.Indent--; writer.WriteLine(); writer.WriteEndTag("div"); } } }
/// <summary> /// Determines if the <paramref name="pagerPosition"/> is one of the defined enumerations. This method is more efficient than using /// <see cref="Enum.IsDefined" />, since <see cref="Enum.IsDefined" /> uses reflection. /// </summary> /// <param name="pagerPosition">An instance of <see cref="PagerPosition" /> to test.</param> /// <returns>Returns true if <paramref name="pagerPosition"/> is one of the defined items in the enumeration; otherwise returns false.</returns> public static bool IsValidPagerPosition(PagerPosition pagerPosition) { switch (pagerPosition) { case PagerPosition.Top: case PagerPosition.Bottom: case PagerPosition.TopAndBottom: break; default: return(false); } return(true); }
public SearchResults(DtoDataSet results, string tableId = "", int recordsPerPage = 50, int recordLimit = int.MaxValue, int currentPage = 1, int tableIndex = 0, string tableCaption = "Search Results", PagerPosition pagerPosition = PagerPosition.Top, Dictionary <string, string> specialColumnAliases = null) : this() { //OverWrite Default Values From Default Constructor Value If Need To TableIndex = tableIndex; RecordsPerPage = recordsPerPage; RecordLimit = recordLimit; TableCaption = tableCaption; PagerPosition = pagerPosition; SpecialColumnAliases = specialColumnAliases; //If user doesn't specify an Id field stick with the random generated Id if its provided. Else generate another unique id if (!string.IsNullOrWhiteSpace(tableId)) { TableId = tableId; } //If its null want to set it to new object to display error messages if (results == null) { Results = new DtoDataSet(); } else { Results = results; } if (string.IsNullOrWhiteSpace(Results.Error) && Results.Ds.Tables != null && Results.Ds.Tables.Count != 0 && Results.Ds.Tables[TableIndex].Rows.Count != 0) { if (Results.Ds.Tables[TableIndex].Rows.Count > RecordLimit) { Results.Ds = ReplaceTable(Results.Ds, TableIndex, GetNRows(Results.Ds.Tables[TableIndex], RecordLimit)); } RecordCount = Results.Ds.Tables[TableIndex].Rows.Count; TotalPages = CountPages(RecordCount, RecordsPerPage); } if (CurrentPage != currentPage && currentPage > 0 && currentPage <= TotalPages) { CurrentPage = currentPage; } }
private void Pager(HtmlTextWriter writer, PagerPosition pos) { //paging is not optimzed for jobs more than 1000, please extend //this code to handle more paging your self. var gridView = Control as GridView; if (gridView != null && (gridView.AllowPaging && gridView.PageCount > 1)) { Table innerTable = null; //will gets pager on top switch (pos) { case PagerPosition.Top: innerTable = gridView.TopPagerRow.Cells[0].Controls[0] as Table; break; default: innerTable = gridView.BottomPagerRow.Cells[0].Controls[0] as Table; break; } //we are not using top & Bottom for now. if (innerTable != null) { var className = string.Empty; className += gridView.PagerStyle.CssClass; writer.WriteLine(); writer.WriteBeginTag("div"); writer.WriteAttribute("class", className); writer.Write(HtmlTextWriter.TagRightChar); writer.Indent++; TableRow row = innerTable.Rows[0]; foreach (Control ctrl in from TableCell cell in row.Cells from Control ctrl in cell.Controls select ctrl) { writer.WriteLine(); ctrl.RenderControl(writer); } writer.Indent--; writer.WriteLine(); writer.WriteEndTag("div"); } } }
protected override void Render(HtmlTextWriter writer) { try { if (this.VirtualItemCount > 0 || this.Rows.Count > 0) { bool ShowTop = false, ShowBottom = false; if (AllowPaging && Visible && VirtualItemCount > 0) { PagerPosition CurrentPosition = this.PagerSettings.Position; ShowTop = CurrentPosition == PagerPosition.Top || CurrentPosition == PagerPosition.TopAndBottom; ShowBottom = CurrentPosition == PagerPosition.Bottom || CurrentPosition == PagerPosition.TopAndBottom; } string PagingText = string.Format(ResourceManager.GetResource("ui.gridview.pagertext"), this.VirtualItemCount, this.PageCount, this.CurrentPageIndex + 1); if (ShowTop) { writer.Write(PagingText); } base.Render(writer); if (ShowBottom) { writer.Write(PagingText); } } else { base.Render(writer); writer.Write(ResourceManager.GetResource("ui.gridview.nodata")); } } catch (Exception ex) { ExceptionManager.Publish(ex); base.Render(writer); } }
protected virtual void BuildPaging(HtmlTextWriter writer, PagerPosition position) { if (AllowPaging && (DataItemCount > 0) && PagerSettings.Visible && (PagerSettings.Position == position || PagerSettings.Position == PagerPosition.TopAndBottom)) { if (PagerTemplate == null) { writer.WriteLine(); writer.WriteBeginTag("div"); writer.WriteAttribute("class", _classPagination); writer.Write(HtmlTextWriter.TagRightChar); writer.Indent++; int start = 0; int end = this.DataItemCount; int pages = end; // Check if we need to display the first and last links bool bIncludeFirstLast = (this.PagerSettings.Mode == PagerButtons.NextPreviousFirstLast) || (this.PagerSettings.Mode == PagerButtons.NumericFirstLast); // Identify which mode of paging we are using switch (this.PagerSettings.Mode) { case PagerButtons.NumericFirstLast: case PagerButtons.Numeric: // Update start/end/pages bool bExceededPageButtonCount = pages > this.PagerSettings.PageButtonCount; if (bExceededPageButtonCount) { start = (PageIndex / PagerSettings.PageButtonCount) * PagerSettings.PageButtonCount; end = Math.Min(start + PagerSettings.PageButtonCount, DataItemCount); } // Write first page link if (bIncludeFirstLast) { if (this.PageIndex > 0) { WritePagingLink(writer, this.PagerSettings.FirstPageText, 1, _classFirstPage); } else { WritePagingLink(writer, this.PagerSettings.FirstPageText, _classFirstPage, _classPagingLinkDisabled); } } // Write first other pages link if (bExceededPageButtonCount && (start > 0)) { WritePagingLink(writer, "...", start, _classOtherPage); } // Write page links for (int iDataItem = start; iDataItem < end; iDataItem++) { string strPage = (iDataItem + 1).ToString(); if (PageIndex == iDataItem) { WritePagingLink(writer, strPage, _classOtherPage, _classActivePage); } else { WritePagingLink(writer, strPage, iDataItem + 1, _classOtherPage); } } // Write last other pages link if (bExceededPageButtonCount && (end < DataItemCount)) { WritePagingLink(writer, "...", end + 1, _classOtherPage); } // Write last page link if (bIncludeFirstLast) { if (this.PageIndex < (this.DataItemCount - 1)) { WritePagingLink(writer, this.PagerSettings.LastPageText, this.DataItemCount, _classLastPage); } else { WritePagingLink(writer, this.PagerSettings.LastPageText, _classLastPage, _classPagingLinkDisabled); } } break; case PagerButtons.NextPreviousFirstLast: case PagerButtons.NextPrevious: // Write first page link // Only implemented when displaying paging links as text instead of an image if (bIncludeFirstLast) { if (String.IsNullOrEmpty(this.PagerSettings.FirstPageImageUrl)) { if (this.PageIndex > start) { WritePagingLink(writer, this.PagerSettings.FirstPageText, start + 1, _classFirstPage); } else { WritePagingLink(writer, this.PagerSettings.FirstPageText, _classFirstPage, _classActivePage); } } } // Write prev page link // Only implemented when displaying paging links as text instead of an image if (String.IsNullOrEmpty(this.PagerSettings.PreviousPageImageUrl)) { // Check if Previous link needs to be disabled if (this.PageIndex > start) { WritePagingLink(writer, this.PagerSettings.PreviousPageText, this.PageIndex, _classPreviousPage); } else { WritePagingLink(writer, this.PagerSettings.PreviousPageText, _classPreviousPage, _classPagingLinkDisabled); } } // Write next page link // Only implemented when displaying paging links as text instead of an image if (String.IsNullOrEmpty(this.PagerSettings.NextPageImageUrl)) { // Check if Next link needs to be disabled if (PageIndex < (end - 1)) { WritePagingLink(writer, this.PagerSettings.NextPageText, this.PageIndex + 2, _classNextPage); } else { WritePagingLink(writer, this.PagerSettings.NextPageText, _classNextPage, _classPagingLinkDisabled); } } // Write last page link // Only implemented when displaying paging links as text instead of an image if (bIncludeFirstLast) { if (String.IsNullOrEmpty(this.PagerSettings.LastPageImageUrl)) { if (this.PageIndex < (end - 1)) { WritePagingLink(writer, this.PagerSettings.LastPageText, pages, _classLastPage); } else { WritePagingLink(writer, this.PagerSettings.LastPageText, _classLastPage, _classActivePage); } } } break; } writer.Indent--; writer.WriteLine(); writer.WriteEndTag("div"); } else // PagerTemplate != null { writer.WriteLine(); writer.WriteBeginTag("div"); writer.WriteAttribute("class", _classPagination); writer.Write(HtmlTextWriter.TagRightChar); writer.Indent++; TableRow pagerRow; if (position == PagerPosition.Top) { pagerRow = TopPagerRow; } else { pagerRow = BottomPagerRow; } foreach (TableCell cell in pagerRow.Cells) { foreach (Control ctrl in cell.Controls) { ctrl.RenderControl(writer); } } writer.Indent--; writer.WriteEndTag("div"); } } }
/// <remarks> /// Patch provided by Wizzard to support PagerTemplate (CodePlex issue #3368). /// </remarks> private void WritePagerSection(HtmlTextWriter writer, PagerPosition pos) { GridView gridView = Control as GridView; if ((gridView != null) && gridView.AllowPaging && gridView.PagerSettings.Visible && (gridView.PageCount > 1) && ((gridView.PagerSettings.Position == pos) || (gridView.PagerSettings.Position == PagerPosition.TopAndBottom))) { GridViewRow pagerRow = (pos == PagerPosition.Top) ? gridView.TopPagerRow : gridView.BottomPagerRow; string className = GetRowClass(gridView, pagerRow); className += " AspNet-GridView-" + (pos == PagerPosition.Top ? "Top " : "Bottom "); //check for PagerTemplate if (gridView.PagerTemplate != null) { if (gridView.PagerStyle != null) { className += gridView.PagerStyle.CssClass; } className = className.Trim(); writer.WriteLine(); writer.WriteBeginTag("div"); writer.WriteAttribute("class", className); writer.Write(HtmlTextWriter.TagRightChar); writer.Indent++; if (pagerRow != null) { foreach (TableCell cell in pagerRow.Cells) { foreach (Control ctrl in cell.Controls) { ctrl.RenderControl(writer); } } } writer.Indent--; writer.WriteEndTag("div"); } else //if not a PagerTemplate { Table innerTable = null; if ((pos == PagerPosition.Top) && (gridView.TopPagerRow != null) && (gridView.TopPagerRow.Cells.Count == 1) && (gridView.TopPagerRow.Cells[0].Controls.Count == 1) && typeof(Table).IsAssignableFrom(gridView.TopPagerRow.Cells[0].Controls[0].GetType())) { innerTable = gridView.TopPagerRow.Cells[0].Controls[0] as Table; } else if ((pos == PagerPosition.Bottom) && (gridView.BottomPagerRow != null) && (gridView.BottomPagerRow.Cells.Count == 1) && (gridView.BottomPagerRow.Cells[0].Controls.Count == 1) && typeof(Table).IsAssignableFrom(gridView.BottomPagerRow.Cells[0].Controls[0].GetType())) { innerTable = gridView.BottomPagerRow.Cells[0].Controls[0] as Table; } if ((innerTable != null) && (innerTable.Rows.Count == 1)) { if (gridView.PagerStyle != null) { className += gridView.PagerStyle.CssClass; } className = className.Trim(); writer.WriteLine(); writer.WriteBeginTag("div"); writer.WriteAttribute("class", className); writer.Write(HtmlTextWriter.TagRightChar); writer.Indent++; TableRow row = innerTable.Rows[0]; foreach (TableCell cell in row.Cells) { foreach (Control ctrl in cell.Controls) { writer.WriteLine(); ctrl.RenderControl(writer); } } writer.Indent--; writer.WriteLine(); writer.WriteEndTag("div"); } } } }
public NextPreviousPager SetPosition(PagerPosition position) { Position = position; return this; }
public NextPreviousPager(string nextText, string nextUrl, string prevText, string prevUrl, IconType nextIcon = null, IconType prevIcon = null, PagerPosition position = PagerPosition.Center, string clientId = null) : base("_NextPreviousPager", clientId) { SetNext(nextText, nextUrl, nextIcon).SetPrevious(prevText, prevUrl, prevIcon).SetPosition(position); }
/// <summary> /// Writes the pager section. /// </summary> /// <param name="writer"> /// The writer. /// </param> /// <param name="pos"> /// The pos. /// </param> /// <remarks> /// </remarks> private void WritePagerSection(HtmlTextWriter writer, PagerPosition pos) { var gridView = this.Control as GridView; if ((gridView != null) && gridView.AllowPaging && ((gridView.PagerSettings.Position == pos) || (gridView.PagerSettings.Position == PagerPosition.TopAndBottom))) { Table innerTable = null; if ((pos == PagerPosition.Top) && (gridView.TopPagerRow != null) && (gridView.TopPagerRow.Cells.Count == 1) && (gridView.TopPagerRow.Cells[0].Controls.Count == 1) && typeof(Table).IsAssignableFrom(gridView.TopPagerRow.Cells[0].Controls[0].GetType())) { innerTable = gridView.TopPagerRow.Cells[0].Controls[0] as Table; } else if ((pos == PagerPosition.Bottom) && (gridView.BottomPagerRow != null) && (gridView.BottomPagerRow.Cells.Count == 1) && (gridView.BottomPagerRow.Cells[0].Controls.Count == 1) && typeof(Table).IsAssignableFrom(gridView.BottomPagerRow.Cells[0].Controls[0].GetType())) { innerTable = gridView.BottomPagerRow.Cells[0].Controls[0] as Table; } if ((innerTable != null) && (innerTable.Rows.Count == 1)) { var className = "AspNet-GridView-Pagination AspNet-GridView-"; className += (pos == PagerPosition.Top) ? "Top " : "Bottom "; className += gridView.PagerStyle.CssClass; className = className.Trim(); writer.WriteLine(); writer.WriteBeginTag("div"); writer.WriteAttribute("class", className); writer.Write(HtmlTextWriter.TagRightChar); writer.Indent++; var row = innerTable.Rows[0]; foreach (TableCell cell in row.Cells) { foreach (Control ctrl in cell.Controls) { writer.WriteLine(); ctrl.RenderControl(writer); } } writer.Indent--; writer.WriteLine(); writer.WriteEndTag("div"); } } }
public static void SettingPaging(this GridViewSettings gridView, GridData gridData, PagerPosition position = PagerPosition.Bottom) { gridView.SettingsPager.Visible = gridData.ShowPager; if (gridData.ShowPager) { gridView.SettingsPager.Position = position; gridView.SettingsPager.FirstPageButton.Visible = true; gridView.SettingsPager.LastPageButton.Visible = true; gridView.SettingsPager.PageSizeItemSettings.Visible = true; gridView.SettingsPager.PageSizeItemSettings.ShowAllItem = true; gridView.SettingsPager.EllipsisMode = PagerEllipsisMode.InsideNumeric; gridView.SettingsPager.PageSizeItemSettings.ShowAllItem = true; gridView.SettingsPager.PageSizeItemSettings.Items = (gridData.PageSizes != null && gridData.PageSizes.Any()) ? gridData.PageSizes : DefaultPageSizeItems; gridView.SettingsPager.AlwaysShowPager = false; } else { gridView.SettingsPager.Mode = GridViewPagerMode.ShowAllRecords; } gridView.SettingsPager.EnableAdaptivity = true; }
/// <summary> /// Determines if the <paramref name="pagerPosition"/> is one of the defined enumerations. This method is more efficient than using /// <see cref="Enum.IsDefined" />, since <see cref="Enum.IsDefined" /> uses reflection. /// </summary> /// <param name="pagerPosition">An instance of <see cref="PagerPosition" /> to test.</param> /// <returns>Returns true if <paramref name="pagerPosition"/> is one of the defined items in the enumeration; otherwise returns false.</returns> public static bool IsValidPagerPosition(PagerPosition pagerPosition) { switch (pagerPosition) { case PagerPosition.Top: case PagerPosition.Bottom: case PagerPosition.TopAndBottom: break; default: return false; } return true; }
public static MvcHtmlString UxNextPrevPager(this HtmlHelper htmlHelper, string nextText = "Next", string nextUrl = null, string previousText = "Previous", string previousUrl = null, IconType nextIcon = null, IconType previousIcon = null, PagerPosition position = PagerPosition.Center, string clientId = null) { var pager = new NextPreviousPager(nextText, nextUrl, previousText, previousUrl, nextIcon, previousIcon, position, clientId); return htmlHelper.RenderUxControl(pager); }