Thursday, March 29, 2012

Setting pager-style in DataGrid

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 WiskerkeHi 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_ItemCreate
d);
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[i];
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.
"Friso Wiskerke" wrote:

> Hi all,
> is it possible to set a separate style in a datagrid pager for the selecte
d
> 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
>
>

0 comments:

Post a Comment