using System; using System.Data; using System.Configuration; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Xml.Linq; using System.Web.DynamicData; namespace Citrus.Data.Core.Demo.Dynamic { public partial class GridViewPager : System.Web.UI.UserControl { private GridView _gridView; protected void Page_Load(object sender, EventArgs e) { Control c = Parent; while (c != null) { if (c is GridView) { _gridView = (GridView)c; break; } c = c.Parent; } } protected void TextBoxPage_TextChanged(object sender, EventArgs e) { if (_gridView == null) { return; } int page; if (int.TryParse(TextBoxPage.Text.Trim(), out page)) { if (page <= 0) { page = 1; } if (page > _gridView.PageCount) { page = _gridView.PageCount; } _gridView.PageIndex = page - 1; } TextBoxPage.Text = (_gridView.PageIndex + 1).ToString(); } protected void DropDownListPageSize_SelectedIndexChanged(object sender, EventArgs e) { if (_gridView == null) { return; } DropDownList dropdownlistpagersize = (DropDownList)sender; _gridView.PageSize = Convert.ToInt32(dropdownlistpagersize.SelectedValue); int pageindex = _gridView.PageIndex; _gridView.DataBind(); if (_gridView.PageIndex != pageindex) { //if page index changed it means the previous page was not valid and was adjusted. Rebind to fill control with adjusted page _gridView.DataBind(); } } protected void Page_PreRender(object sender, EventArgs e) { if (_gridView != null) { LabelNumberOfPages.Text = _gridView.PageCount.ToString(); TextBoxPage.Text = (_gridView.PageIndex + 1).ToString(); DropDownListPageSize.SelectedValue = _gridView.PageSize.ToString(); } } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)