Setting pager-style in DataGrid

F

Friso Wiskerke

Hi all,

is it possible to set a separate style in a datagrid pager for the selected
page to make it more clear for the user which page is selected?
For example: page 3 is selected out of the 8 possible pages and the number 3
is then displayed in bold and with an alternate color.

There's a pager style but there is no setting for the selected page.

TIA
Friso Wiskerke
 
G

Guest

Hi Frisko,

you can achieve the same by modifying the pager properties in the DataGrid's
ItemCreated event.

Add the following event handler in the InitializeComponent() method -

this.DataGrid1.ItemCreated += new
System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemCreated);

The DataGrid ItemCreated method code will be -

private void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e)
{
if ( e.Item.ItemType == ListItemType.Pager)
{
TableCell Pager = (TableCell) e.Item.Controls[0];
for(int i = 0;i < Pager.Controls.Count ; i++ )
{
object pageNumbers = Pager.Controls;
if (pageNumbers.GetType().Name == "DataGridLinkButton")
{
LinkButton lbt = (LinkButton) pageNumbers;
lbt.ForeColor = System.Drawing.Color.Gray;
}
else if(pageNumbers.GetType().Name == "Label")
{
Label lbl = (Label) pageNumbers;
lbl.ForeColor = System.Drawing.Color.Black;
lbl.Font.Bold = true;
}
}
}
}

HTH.
 

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

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top