Code-Behind
Code
//Page Load
Event
protected void Page_Load(object sender, EventArgs
e)
{
if (!IsPostBack)
{
BindMngRegistration();
}
}
//Load or Bind
the Data to Dataset with gridview or Datalist
public void BindMngRegistration()
{
DataSet ds = BLLRegisrationOnline.ViewManageRegistration();
_PageDataSource.DataSource = ds.Tables[0].DefaultView;
_PageDataSource.AllowPaging = true;
_PageDataSource.PageSize
= Convert.ToInt32(GVRegView.PageSize);
_PageDataSource.CurrentPageIndex
= CurrentPage;
ViewState["TotalPages"] =
_PageDataSource.PageCount;
this.lblPageInfo.Text = "Page
" + (CurrentPage + 1) + " of
" + _PageDataSource.PageCount;
this.lbtnPrevious.Enabled =
!_PageDataSource.IsFirstPage;
this.lbtnNext.Enabled = !_PageDataSource.IsLastPage;
this.lbtnFirst.Enabled =
!_PageDataSource.IsFirstPage;
this.lbtnLast.Enabled = !_PageDataSource.IsLastPage;
//Bind With Control
this.GVRegView.DataSource = _PageDataSource;
this.GVRegView.DataBind();
this.doPaging();
}
//Write This
Code For the Number of Record to display at Lable
protected void
dlPaging_ItemDataBound(object sender, DataListItemEventArgs e)
{
if
(e.Item.ItemType != ListItemType.Separator)
{
LinkButton
lnkbtnPage = (LinkButton)e.Item.FindControl("lnkbtnPaging");
if
(lnkbtnPage.CommandArgument.ToString() == CurrentPage.ToString())
{
lnkbtnPage.Enabled = false;
lnkbtnPage.Style.Add("fone-size", "14px");
lnkbtnPage.Font.Bold = true;
}
}
}
//display the
current page of the number of page like (5 of 15)
protected void dlPaging_ItemCommand(object source, DataListCommandEventArgs
e)
{
if (e.CommandName.Equals("Paging"))
{
CurrentPage = Convert.ToInt16(e.CommandArgument.ToString());
this.BindMngRegistration();
}
}
// Page
Datasource Object for pagging
#region PagedDataSource
PagedDataSource _PageDataSource = new PagedDataSource();
#endregion
//Properties of
Paging for next,first ,last,previous
#region Private Properties
private int
CurrentPage
{
get
{
object objPage = ViewState["_CurrentPage"];
int _CurrentPage = 0;
if (objPage == null)
{
_CurrentPage = 0;
}
else
{
_CurrentPage = (int)objPage;
}
return _CurrentPage;
}
set { ViewState["_CurrentPage"]
= value; }
}
private int fistIndex
{
get
{
int _FirstIndex = 0;
if (ViewState["_FirstIndex"]
== null)
{
_FirstIndex = 0;
}
else
{
_FirstIndex = Convert.ToInt32(ViewState["_FirstIndex"]);
}
return _FirstIndex;
}
set { ViewState["_FirstIndex"]
= value; }
}
private int lastIndex
{
get
{
int _LastIndex = 0;
if (ViewState["_LastIndex"]
== null)
{
_LastIndex = 0;
}
else
{
_LastIndex = Convert.ToInt32(ViewState["_LastIndex"]);
}
return _LastIndex;
}
set { ViewState["_LastIndex"]
= value; }
}
#endregion
//Events of Paging
#region "Custom Paging"
protected void
lbtnFirst_Click(object sender, EventArgs e)
{
CurrentPage =
0;
this.BindMngRegistration();
}
protected void
lbtnPrevious_Click(object sender, EventArgs e)
{
CurrentPage -=
1;
this.BindMngRegistration();
}
protected void
lbtnNext_Click(object sender, EventArgs e)
{
CurrentPage +=
1;
this.BindMngRegistration();
}
protected void
lbtnLast_Click(object sender, EventArgs e)
{
CurrentPage = (Convert.ToInt32(ViewState["TotalPages"])
- 1);
this.BindMngRegistration();
}
#endregion

Join the conversation! Your thoughts help the community grow.