GridView Paging and Sorting with url parameters in asp.net c#
Many times we want to want
to add actual page number to the url. This code will help you .
Code behind:-
We need to call this
method on page index
protected void
Gridview1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
e.Cancel = true;
int
index = e.NewPageIndex + 1;
string
urlPath = HttpContext.Current.Request.Url.AbsoluteUri;
Uri uri
= new Uri(urlPath);
string url
= uri.GetLeftPart(UriPartial.Path);
Response.Redirect(string.Format("{0}?page={1}",
url, index));
}
We can call
this method on page load
protected void
Page_Load(object sender, EventArgs e)
{
if
(!IsPostBack)
{
if
(Request.QueryString["page"] != null)
{
int
index = int.Parse(Request.QueryString["page"]);
Gridview1.PageIndex = index-1;
Gridview1.DataBind();
bindgirdview();
}
else
{
bindgirdview();
}
}
}
GridView Paging and Sorting with url parameters in asp.net c#
Reviewed by NEERAJ SRIVASTAVA
on
8:17:00 PM
Rating:
No comments: