using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using System.Collections.Generic;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
            
    }
    private string _pageComboID;

    public string PageComboID
    {
        get
        {
            return _pageComboID;
        }
        set
        {
            _pageComboID = value;
        }
    }

    protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridPagerItem)
        {
            RadComboBoxItem item;
            RadComboBox PageSizeComboBox = (RadComboBox)e.Item.FindControl("PageSizeComboBox");

            //get the client id of the combo so that the custom css style be applied to the combo in the grid's pager;
            //if the style were defined without the #<%= PageComboID %>_DropDown in front, the style whould be applied
            //to any RadComboBox on the page.
            this._pageComboID = PageSizeComboBox.ClientID;

            PageSizeComboBox.Width = Unit.Pixel(65);

            item = new RadComboBoxItem("150", "150");

            item.Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID);

            if (PageSizeComboBox.Items.FindItemByText(item.Text) == null)
            {
                PageSizeComboBox.Items.Add(item);
            }

            item = new RadComboBoxItem("250", "250");

            item.Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID);

            if (PageSizeComboBox.Items.FindItemByText(item.Text) == null)
            {
                PageSizeComboBox.Items.Add(item);
            }


            item = new RadComboBoxItem("500", "500");
            item.Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID);

            if (PageSizeComboBox.Items.FindItemByText(item.Text) == null)
            {
                PageSizeComboBox.Items.Add(item);
            }

            item = new RadComboBoxItem("1000", "1000");
            item.Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID);

            if (PageSizeComboBox.Items.FindItemByText(item.Text) == null)
            {
                PageSizeComboBox.Items.Add(item);
            }


            PageSizeComboBox.Items.Sort(new PagerRadComboBoxItemComparer());
        }
    }
}

public class PagerRadComboBoxItemComparer : IComparer<RadComboBoxItem>, IComparer
{


    public int Compare(RadComboBoxItem x, RadComboBoxItem y)
    {

        int rValue = 0;
        int lValue = 0;

        if (Int32.TryParse(x.Value, out lValue) && Int32.TryParse(y.Value, out rValue))
        {
            return lValue.CompareTo(rValue);
        }
        else
        {
            return x.Value.CompareTo(y.Value);

        }
    }

    public int Compare(object x, object y)
    {
        return Compare((RadComboBoxItem)x, (RadComboBoxItem)y);
    }


}
