A Place for C Sharpers/.Netters

I Will do coding till last moment of life-Kiran Patil

Posts Tagged ‘Default paging’

Adding Total number of rows and formatting PagerRow In gridview with Default paging

Posted by kiranpatils on April 3, 2008

Hi..i have one grid which shows data from objectconatinerdatasource. I am using Default paging which shows pager row like this

1 2 3 4 5

But i want like this

1 2 3 4 5 (Page <CURRENT PAGENUMBER> of <TotalRecords> )

How to achieve this??

Some one will say use custom paging..But i am disagree with them. Because when i can do things easily then why should i do it other way….So here is my way to do this.

1. Handle your grid’s DataBound event.

2. Handler of it will do my task.

protected void GridViewEmp_DataBound(object sender, EventArgs e)
{
if (GridViewEmp!= null)
{
//Showing Search Result Count
//Get Top Pager Row from a gridview
GridViewRow row = GV_SearchBooker.TopPagerRow;
if (row != null)
{

//create one Cell for adding in my current paging strip

TableCell infocell = new TableCell();
infocell.Text = ” Page ” + (GridViewEmp.PageIndex + 1).ToString() + ” of ” +                      GridViewEmp.PageCount.ToString() +
“(” + _totalrowscount.ToString() + ” Records)”;

//Getting table which shows PagingStrip

Table tbl = (Table)row.Cells[0].Controls[0]; //Will Find table                                      tbl.Rows[0].Cells.Add(infocell);
}
}
}

Explanation:

This line needs more exp as i think:

Table tbl = (Table)row.Cells[0].Controls[0]; //Will Find table

row = will have TopRow

it has cells collection cells[0] means 1 2 3 4 5 6 and out of it controls[0] means that <table> just add one <td> that’s it by using Tablecell..

Posted in ASP.NET | Tagged: , | Leave a Comment »