Subscribe:

Pages

February 20, 2008

GridView Pagination Template

Here is C# code to display gridview Pagination in the form
'1 2 3 4 5 6 7 Records 1 - 20 of 132 '

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
// Use the RowType property to determine whether the
// row being created is the Pager row.
//count is total no of records
if (e.Row.RowType == DataControlRowType.Pager){
Label total = new Label();
total.Text = "Records " + (GridView1.PageIndex == 0 ? 1 : ((GridView1.PageIndex) * 10) + 1).ToString() + " - " + (GridView1.PageIndex == (count / 10) ? count : ((GridView1.PageIndex + 1) * 10)).ToString() + " of " + count.ToString();
total.Font.Bold = true;
TableCell tot = new TableCell();
tot.Controls.Add(total);
tot.Attributes["width"] = "100%";
tot.Attributes["align"] = "right";
Table dtemp = (Table)e.Row.Cells[0].Controls[0];
dtemp.Rows[0].Cells.Add(tot);
}
}

0 comments:

Post a Comment