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 Telerik.Web.UI;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Drawing;
using System.IO;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Text;
using Telerik.Web.UI.GridExcelBuilder;

public partial class _Default : System.Web.UI.Page
{
    static bool shouldDisableCommandItem = false;
    static bool shouldDisableEditItems = false;

    protected void Button1_Click(object sender, EventArgs e)
    {
        RadGrid1.MasterTableView.ExportToExcel();
    }

    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.EditCommandName)
        {
            shouldDisableCommandItem = true;
        }
        else if (e.CommandName == RadGrid.InitInsertCommandName)
        {
            shouldDisableEditItems = true;
        }
        else if (e.CommandName == RadGrid.CancelCommandName)
        {
            shouldDisableCommandItem = false;
            shouldDisableEditItems = false;
        }
    }
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        if (shouldDisableEditItems)
        {
            foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
            {
                (dataItem["EditColumn"].Controls[0] as LinkButton).Enabled = false;
            }
        }
        else if (shouldDisableCommandItem)
        {
            GridCommandItem commandItem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
            commandItem.Enabled = false;
        }
    }
}








