datagrid question

  • Thread starter Thread starter NuB
  • Start date Start date
N

NuB

I have a datagrid on my page and allow paging, how can i add text where my
pages numbers are?

example:

Instead of seeing 1 2 3 4

i want to see Page 1 2 3 4 Show All Total of rows 200


how can i do that in the grid?
 
when i put anything in the footer tag, when i go back to design view, I get
error creating control for my grid.
 
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();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top