using System;
using System.Data;
using Telerik.Web.UI;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AlphaCommandsSliderPager
{
	public partial class DefaultCS : System.Web.UI.Page
	{
        public void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridCommandItem)
            {
                GridCommandItem commandItem = (e.Item as GridCommandItem);
                PlaceHolder container = (PlaceHolder)commandItem.FindControl("PlaceHolder1");

                for (int i = 65; i < 65 + 25; i++)
                {
                    LinkButton linkButton1 = new LinkButton();
                    LiteralControl lc = new LiteralControl("&nbsp;&nbsp;");

                    linkButton1.Text = "" + (char)i;

                    linkButton1.CommandName = "alpha";
                    linkButton1.CommandArgument = "" + (char)i;

                    container.Controls.Add(linkButton1);
                    container.Controls.Add(lc);
                }

                LiteralControl lcLast = new LiteralControl("&nbsp;");
                container.Controls.Add(lcLast);

                LinkButton linkButtonAll = new LinkButton();
                linkButtonAll.Text = "All";
                linkButtonAll.CommandName = "NoFilter";
                container.Controls.Add(linkButtonAll);
            }

        }

        public void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            String value = null;
            switch (e.CommandName)
            { 
                case ("alpha"):
                    {
                        value = string.Format("{0}%", e.CommandArgument);
                        break;
                    }
                case ("NoFilter"):
                    {
                        value = "%";
                        break;
                    }
            }

            SqlDataSource1.SelectParameters["Letter"].DefaultValue = value;
            RadGrid1.Rebind();
        }
    }
}
