Thread: ASP.NET/Gridview custome paging

Gridview custome paging
We always want our pages to be SEO, so we need to replace standard ASP.NET pager with URL links...

A News Article List in an ASP.NET GridView Control With Custom Paging

ASP.NET paging control

Pager Control for ASP.NET

Custom paging with ASP.NET GridView (jQuery)



Re: Gridview custome paging

string forumPage = this.Request.QueryString["pg"];

int pageNumber = 0;

int.TryParse(forumPage, out pageNumber);

FillForumGrid(Convert.ToInt32(forumID), pageNumber, "", 25);

protected void FillForumGrid(int forumId, int iCurrentPage, string sortExpression, int iMaxRows)

{

int iTotal = Post.GetThreadCount(forumId);

 

int startRowIndex = iCurrentPage * iMaxRows;

var dtPosts = Post.GetThreads(forumId, sortExpression, startRowIndex, iMaxRows);

gvwThreads.DataSource = dtPosts;

gvwThreads.DataBind();

// Paging

if (gvwThreads.Rows.Count < 1)

{

divPager.InnerHtml = "";

}

else

{

int iPages = 0;

int iRemainder = 0;

iPages = iTotal / iMaxRows;

iRemainder = iTotal % iMaxRows;

if (iRemainder > iMaxRows)

{

iPages += 1;

}

if (iPages > 1)

{

divPager.InnerHtml = "Page: ";

 

for (int i = 0; i < iPages; i++)

{

if (i != iCurrentPage)

{

divPager.InnerHtml += "<a href='" + "" + "?pg=" + i + "'>" + i + "</a>";

}

else

{

divPager.InnerHtml += i.ToString();

}

if (i < iPages)

{

divPager.InnerHtml += " | ";

}

}

}

}

}