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;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        RadGrid1.ItemCreated += new Telerik.Web.UI.GridItemEventHandler(RadGrid1_ItemCreated);
        RadGrid1.PreRender += new EventHandler(RadGrid1_PreRender);
        RadGrid1.ItemCommand += new GridCommandEventHandler(RadGrid1_ItemCommand);
    }

    void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.ExpandCollapseCommandName)
        {
            if (Session[e.Item.ItemIndex.ToString()] != null)
                Session[e.Item.ItemIndex.ToString()] = !(bool)Session[e.Item.ItemIndex.ToString()];
            else
                Session[e.Item.ItemIndex.ToString()] = true;
        }
    }

    void RadGrid1_PreRender(object sender, EventArgs e)
    {
        foreach (GridItem item in RadGrid1.MasterTableView.Items)
        {
            if (Session[item.ItemIndex.ToString()] != null)
            {
                item.Expanded = (bool)Session[item.ItemIndex.ToString()];
            }
        }
    }

    void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {   
            //used for hiding the expand/collapse image of the item

            //GridDataItem item = (GridDataItem)e.Item;
            //item["ExpandColumn"].Controls[0].Visible = false;
        }
    }
}