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

public partial class _Default : System.Web.UI.Page
{
    private Hashtable _ordersEditedState;
    public void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this._ordersEditedState = null;
            this.Session["_ordersEditedState"] = null;
        }
    }
    private Hashtable EditedStates
    {
        get
        {
            if (this._ordersEditedState == null)
            {
                _ordersEditedState = this.Session["_ordersEditedState"] as Hashtable;
                if (_ordersEditedState == null)
                {
                    _ordersEditedState = new Hashtable();
                    this.Session["_ordersEditedState"] = _ordersEditedState;
                }
            }

            return this._ordersEditedState;
        }
    }
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.Item.OwnerTableView.OwnerGrid.EditIndexes.Count > 0)
        {
            switch (MyCommandName.Value)
            {
                case "Page":
                    if (e.CommandName == RadGrid.PageCommandName)
                    {
                        MyCommandName.Value = "";
                        this._ordersEditedState = null;
                        this.Session["_ordersEditedState"] = null;
                        e.Item.FireCommandEvent(RadGrid.UpdateEditedCommandName, String.Empty);
                    }
                    break;
                case "Edit":
                    if (e.CommandName == RadGrid.EditCommandName)
                    {
                        MyCommandName.Value = "";
                        e.Item.FireCommandEvent(RadGrid.UpdateEditedCommandName, String.Empty);
                    }
                    break;
                default:
                    if (e.CommandName == RadGrid.UpdateCommandName)
                    {
                        this._ordersEditedState = null;
                        this.Session["_ordersEditedState"] = null;
                    }
                    break;
            }
        }
    }

    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
    
    }
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item.IsInEditMode)
        {
            this.EditedStates[(e.Item as GridEditFormItem).ParentItem.ItemIndexHierarchical] = true;
        }
    }
    protected void RadGrid1_DataBound(object sender, EventArgs e)
    {
        string[] indexes = new string[this.EditedStates.Keys.Count];
        this.EditedStates.Keys.CopyTo(indexes, 0);
        ArrayList arr = new ArrayList(indexes);
        arr.Sort();
        foreach (string key in arr)
        {
            bool value = (bool)this.EditedStates[key];
            if (value)
            {
                RadGrid1.Items[key].Edit = true;
            }
        }
    }
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {

    }
}
