handle the ItemCreated event like this:
void grid1_ItemCreated(object sender, DataGridItemEventArgs e)
{
//convert sender to grid type, so we don't have to use its name:
DataGrid grid = (DataGrid) sender;
if(e.Item.ItemType == ListItemType.Pager)
{
Literal prefix = new Literal();
prefix.Text = "Page ";
//add the 'Page' prefix at beginning of pager:
e.Item.Cells[0].Controls.AddAt(0, prefix);
LinkButton btnShowAll = new LinkButton();
btnShowAll.Text = "Show All";
btnShowAll.Click += new EventHandler(btnShowAll_Click);
//add the link button at end of pager:
e.Item.Cells[0].Controls.Add(btnShowAll);
Literal suffix = new Literal();
suffix.Text = String.Format(" Number of records: {0}",
grid.VirtualItemCount);
//add record count text at end:
e.Item.Cells[0].Controls.Add(suffix);
}
}
void btnShowAll_Click(object sender, EventArgs e)
{
//set the page size to the virtual item count, ie no paging, but still
shows pager control:
grid1.PageSize = grid1.VirtualItemCount;
BindGrid();
}