Friday, May 22, 2009

Pagination Custamization

Pagination Custamization:

1).aspx/.ascx Design View







2).aspx.cs/.ascx.cs


private int intCurrentselectPage;

#region CurrentselectPage
public int CurrentSelectPage
{
get
{
return intCurrentselectPage;
}
set
{
intCurrentselectPage = value;
}
}
#endregion


protected void grdNewsList_DataBound(object sender, EventArgs e)
{
if (grdNewsList.Rows.Count > 0)
{
GridViewRow gNavFooter = grdNewsList.BottomPagerRow;
LinkButton lbP = gNavFooter.FindControl("lbPrev") as LinkButton;
LinkButton lbN = gNavFooter.FindControl("lbNext") as LinkButton;
try
{
if (grdNewsList.PageIndex == 0)
{
lbP.Enabled = false;
}

int iStartIndex = 0;
int iCurrentPage = CurrentSelectPage + 1;

int iCalc = (iCurrentPage / 5) + ((iCurrentPage % 5) >= 1 ? 1 : (iCurrentPage % 5));

if (iCalc > 1)
{
iStartIndex = (((iCalc * 5) - 5) + 1);
}
else
{
iStartIndex = 1;
}

for (int i = 1; i <= 5; i++)
{
LinkButton lb = gNavFooter.FindControl("lb" + i.ToString()) as LinkButton;

lb.Text = iStartIndex.ToString();
lb.CommandArgument = iStartIndex.ToString();
if (iStartIndex > grdNewsList.PageCount)
{
lb.Visible = false;
}
if (iStartIndex == grdNewsList.PageIndex + 1)
{
lb.Enabled = false;
}
iStartIndex++;
}

if (grdNewsList.PageIndex == grdNewsList.PageCount - 1)
{
lbN.Enabled = false;
}
}
catch (Exception ex)
{
throw (ex);
}
}
}


protected void grdNewsList_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
CurrentSelectPage = e.NewPageIndex;
grdNewsList.PageIndex = e.NewPageIndex;
DisplayFromListPublishedNews(); // Bind the Method again.
}

Copyright © 2009 Angel