using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

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

    }
    protected void ToggleRowSelection(object sender, EventArgs e)
    {
        ((sender as CheckBox).Parent.Parent as GridItem).Selected = (sender as CheckBox).Checked;
    }

    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            e.Item.PreRender += new EventHandler(RadGrid1_ItemPreRender);
        }
    }

    private void RadGrid1_ItemPreRender(object sender, EventArgs e)
    {
        ((sender as GridDataItem)["CheckBoxTemplateColumn"].FindControl("CheckBox1") as CheckBox).Checked = (sender as GridDataItem).Selected;
    }
    protected void ToggleSelectedState(object sender, EventArgs e)
    {
        if ((sender as CheckBox).Checked)
        {
            foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
            {
                (dataItem.FindControl("CheckBox1") as CheckBox).Checked = true;
                dataItem.Selected = true;
            }
        }
        else
        {
            foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
            {
                (dataItem.FindControl("CheckBox1") as CheckBox).Checked = false;
                dataItem.Selected = false;
            }
        }
    }
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        string text = "Selected rows count is: " + RadGrid1.SelectedItems.Count;
        RadGrid1.Controls.Add(new LiteralControl(string.Format("<span style='color:yellow;font-weight:bolder;'>{0}</span>", text)));
    }

}
