|
using System;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.DynamicData;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DynamicDataTest
{
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(CultureInfo.CurrentCulture);
}
protected void DropDownListPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
if (_gridView == null)
{
return;
}
DropDownList dropdownlistpagersize = (DropDownList)sender;
_gridView.PageSize = Convert.ToInt32(dropdownlistpagersize.SelectedValue, CultureInfo.CurrentCulture);
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(CultureInfo.CurrentCulture);
TextBoxPage.Text = (_gridView.PageIndex + 1).ToString(CultureInfo.CurrentCulture);
DropDownListPageSize.SelectedValue = _gridView.PageSize.ToString(CultureInfo.CurrentCulture);
}
}
}
}
|
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.
I Started my Programming career with C++. Later got a chance to develop Windows Form applications using C#. Currently using C#, ASP.NET & ASP.NET MVC to create Information Systems, e-commerce/e-governance Portals and Data driven websites.
My interests involves Programming, Website development and Learning/Teaching subjects related to Computer Science/Information Systems. IMO, C# is the best programming language and I love working with C# and other Microsoft Technologies.
- Microsoft Certified Technology Specialist (MCTS): Web Applications Development with Microsoft .NET Framework 4
- Microsoft Certified Technology Specialist (MCTS): Accessing Data with Microsoft .NET Framework 4
- Microsoft Certified Technology Specialist (MCTS): Windows Communication Foundation Development with Microsoft .NET Framework 4
If you like my articles, please visit my website for more: www.rahulrajatsingh.com[^]