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;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data.Common;
using System.ComponentModel;
using System.IO;
using System.Xml;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Xsl;

public partial class _Default : System.Web.UI.Page
{

    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        if (!e.IsFromDetailTable)
        {
            RadGrid1.DataSource = GetDataTable("SELECT * FROM Customers");
        }
    }

    protected void RadGrid1_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
    {
        GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
        switch (e.DetailTableView.Name)
        {
            case "DetailTable":
                {
                    string CustomerID = dataItem.GetDataKeyValue("CustomerID").ToString();
                    e.DetailTableView.DataSource = GetDataTable("SELECT * FROM Orders WHERE CustomerID = '" + CustomerID + "'");
                    break;
                }
         
        }
    }

    public DataTable GetDataTable(string query)
    {
        OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("~/App_Data/Nwind.mdb"));
        OleDbDataAdapter adapter = new OleDbDataAdapter();
        adapter.SelectCommand = new OleDbCommand(query, conn);
        DataTable myDataTable = new DataTable();
        conn.Open();
        try
        {
            adapter.Fill(myDataTable);
        }
        finally
        {
            conn.Close();
        }

        return myDataTable;
    }
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {

    }



    
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == "CopyCommand")
        {
            e.Canceled = true;
            e.Item.OwnerTableView.InsertItem();

            //GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
            //HtmlTable formTable = insertedItem.FindControl("formTable") as HtmlTable;
            //HtmlTable copyTable = insertedItem.FindControl("copyTable") as HtmlTable;

            //formTable.visible = false;
            //copyTable.visible = true;
        }  

    }
}









