By default paging combo includes 10, 20 and 50 page sizes, regardless of number of records displayed in the grid (i.e. if records counts to 11 then also page size combo displays 10, 20 and 50).
If we want to customize the page size combo items to show
- Records count > 10 then page size items should show 10 and 20
- Records count >= 20 then page size items should show 10, 20 and 50
In order to achieve the above functionality, we will be using RadGrid ItemCreated and ItemEvent events, refer the below code.
private int totalItemCount; protected void RadGrid1_ItemEvent(object sender, GridItemEventArgs e) { if (e.EventInfo is GridInitializePagerItem) { totalItemCount = (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount; } } protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) { if (e.Item is GridPagerItem) { GridPagerItem pagerItem = (GridPagerItem)e.Item; RadComboBox pageSizeCombo = (RadComboBox)pagerItem.FindControl("PageSizeComboBox"); for (int i = 0; i < pageSizeCombo.Items.Count; i++) { RadComboBoxItem item = pageSizeCombo.Items[i]; if (Convert.ToInt32(item.Value) > totalItemCount) { i--; pageSizeCombo.Items.Remove(item.Index); } } if (totalItemCount != Convert.ToInt32(pageSizeCombo.Items[pageSizeCombo.Items.Count - 1].Value)) { RadComboBoxItem item = new RadComboBoxItem(); item = new RadComboBoxItem(totalItemCount.ToString(), totalItemCount.ToString()); item.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID); pageSizeCombo.Items.Add(item); } // If you lost selected value in Pagesize combo //pageSizeCombo.FindItemByValue(e.Item.OwnerTableView.PageSize.ToString()).Selected = true; } }
<telerik:radgrid allowpaging="true" id="RadGrid1" runat="server"> <mastertableview> <pagerstyle alwaysvisible="true"></pagerstyle> . . . . . . . . </mastertableview> </telerik:radgrid>
private int totalItemCount; protected void RadGrid1_ItemEvent(object sender, GridItemEventArgs e) { if (e.EventInfo is GridInitializePagerItem) { totalItemCount = (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount; } } protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) { if (e.Item is GridPagerItem) { GridPagerItem pagerItem = (GridPagerItem)e.Item; RadComboBox PageSizeCombo = (RadComboBox)pagerItem.FindControl("PageSizeComboBox"); RadComboBoxItem item1 = new RadComboBoxItem(); item1 = new RadComboBoxItem("Show All", totalItemCount.ToString()); item1.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID); PageSizeCombo.Items.Add(item1); } }
The page size which we have selected (10)is changing back to the default one(here 5) in radgrid.
ReplyDeleteI can't changed page size in radgrid of pagesizecombobox.
Please help me!
Have you tried with below code snippet.
ReplyDelete// If you lost selected value in Pagesize combo
//pageSizeCombo.FindItemByValue(e.Item.OwnerTableView.PageSize.ToString()).Selected = true;
How do we default the PageSizeComboBox to "Show All", thus making the initial default view to showing all rows?
ReplyDeleteOn prerender method you have to reset the pagesize of radgrid and then rebind the radgrid.
ReplyDeletehttps://saglamproxy.com
ReplyDeletemetin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
HZ8H