Accessing the Elements of Advanced Type Pager
When using the advanced grid pager/slider, you can customize the properties of the buttons or labels inside the pager or the slider pager itself. The following steps describe how to access these controls:
-
Create a handler for the grid's ItemCreated event.
-
In the event handler, check if e.Item is an instance of GridPagerItem.
-
Use the FindControl method of e.Item to locate the controls inside the pager. The following table lists the ID's of the controls in the pager when Mode is "NextPrevAndNumeric":
Control Type ID "Page Size:" text Label ChangePageSizeLabel "Page Size" combo box RadComboBox PageSizeComboBox Example:
C#protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridPagerItem) { Label lblPageSize = (Label)e.Item.FindControl("ChangePageSizeLabel"); lblPageSize.Text = "Number of items:"; } }
VBProtected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles RadGrid1.ItemDataBound() If TypeOf e.Item Is GridPagerItem Then Dim lblPageSize As Label = DirectCast(e.Item.FindControl("ChangePageSizeLabel"), Label) lblPageSize.Text = "Number of items:" End If End Sub
-
The following table lists the ID's of the controls in the pager when Mode is "Advanced" or "Slider":
Control | Type | ID |
---|---|---|
"Go to page" text | Label | GoToPageLabel |
"Go to page" input | RadNumericTextBox | GoToPageTextBox |
"Go to page" " of " text | Label | PageOfLabel |
"Go to page" link button | Button | GoToPageLinkButton |
"Change page size" text | Label | ChangePageSizeLabel |
"Change page size" input | RadNumericTextBox | ChangePageSizeTextBox |
"Change page size" link button | Button | ChangePageSizeLinkButton |
Slider pager | RadSlider | GridSliderPager |
<telerik:RadGrid
ID="RadGrid1"
runat="server"
Width="95%"
Skin="Vista"
AllowSorting="True"
DataSourceID="SqlDataSource1"
AllowPaging="True" PageSize="5"
OnItemCreated="RadGrid1_ItemCreated">
<PagerStyle Mode="Advanced" />
<MasterTableView Width="100%" DataSourceID="AccessDataSource1" />
</telerik:RadGrid>
When setting the PageOfLabel, in order to to display the page count number, you would need to append it to the label text as demonstrated below:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridPagerItem)
{
GridPagerItem item = e.Item as GridPagerItem;
Label pageOfLabel = e.Item.FindControl("PageOfLabel") as Label;
pageOfLabel.Text = "OF " + item.Paging.PageCount.ToString();
}
}