Change RadGrid PageSize Dropdown


Introduction:

Telerik’s RadGrid provides in-built functionality for paging. User have to select the number of records from the Page Size combo box (default is 10, 20 and 50) and selected number of records is going to display in RadGrid. But we can also change the Page Size in combo box as per our requirement. Following is the code to do the same:

Code:

protectedvoid grdViewReport_ItemDataBound(object sender, GridItemEventArgs e)

{

if (e.Item isGridPagerItem)

{

RadComboBox PageSizeCombo = (RadComboBox)e.Item.FindControl(“PageSizeComboBox”);

PageSizeCombo.Items.Clear();

PageSizeCombo.Items.Add(newRadComboBoxItem(“100”));

PageSizeCombo.FindItemByText(“100”).Attributes.Add(“ownerTableViewId”, grdViewReport.MasterTableView.ClientID);

PageSizeCombo.Items.Add(newRadComboBoxItem(“200”));

PageSizeCombo.FindItemByText(“200”).Attributes.Add(“ownerTableViewId”, grdViewReport.MasterTableView.ClientID);

PageSizeCombo.Items.Add(newRadComboBoxItem(“500”));

PageSizeCombo.FindItemByText(“500”).Attributes.Add(“ownerTableViewId”, grdViewReport.MasterTableView.ClientID);

PageSizeCombo.FindItemByText(e.Item.OwnerTableView.PageSize.ToString()).Selected = true;

}

}

Advertisements