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;
using System.Windows;
using System.IO;

public partial class _Default : System.Web.UI.Page 
{
    RadGrid gridTest;

         public _Default()   
        {   
            this.Init += new EventHandler(Page_Init);   
        }   
  
        void Page_Init(object sender, EventArgs e)   
        {   
            BuildGrid();   
        }  
  
        protected void BuildGrid()   
        {   
  
            //Instantiate grid   
            gridTest = new RadGrid();   
            gridTest.ID = "gridTest";   
  
            //Add gridTest Event Handlers   
            gridTest.NeedDataSource += new GridNeedDataSourceEventHandler(gridCurrentWorkflows_NeedDataSource);   
            gridTest.ItemCommand += new GridCommandEventHandler(gridCurrentWorkflows_ItemCommand);   
            gridTest.DetailTableDataBind += new GridDetailTableDataBindEventHandler(gridCurrentWorkflows_DetailTableDataBind);   
  
            //Configure gridTest   
            gridTest.Width = Unit.Percentage(100);   
            gridTest.EnableViewState = true;   
            gridTest.Skin = "Default";   
            gridTest.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;   
            gridTest.MasterTableView.Name = "MasterTable";   
            gridTest.AllowMultiRowSelection = false;   
            gridTest.AutoGenerateColumns = false;   
            gridTest.MasterTableView.HierarchyDefaultExpanded = true;   
            gridTest.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerBind;   
            gridTest.MasterTableView.ExpandCollapseColumn.Display = false;   
            gridTest.ClientSettings.Selecting.AllowCellSelect = false;   
            gridTest.ClientSettings.Selecting.AllowColumnSelect = false;   
            gridTest.ClientSettings.Selecting.AllowRowSelect = true;   
            gridTest.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;   
            gridTest.GroupingEnabled = false;   
            gridTest.ClientSettings.Resizing.AllowRowResize = false;   
            gridTest.ClientSettings.EnablePostBackOnRowClick = true;   
  
            GridTableView gtSC = new GridTableView();   
            gtSC.Width = Unit.Percentage(100);   
            gtSC.ShowHeader = false;   
            gtSC.GridLines = GridLines.None;   
            gtSC.HorizontalAlign = HorizontalAlign.Left;   
            gtSC.Name = "DetailTable";   
            //gridTest.MasterTableView.DetailTables.Add(gtSC);

            //Single Template column to disply all values for SC row   
            GridTemplateColumn colTemplate = new GridTemplateColumn();
            colTemplate.ItemTemplate = new DetailColumnTemplate();
            colTemplate.EditFormHeaderTextFormat = "";   

            gtSC.Columns.Add(colTemplate);
            gridTest.MasterTableView.DetailTables.Add(gtSC);
  
            GridBoundColumn c1 = new GridBoundColumn();   
            c1.DataField = "Field1";   
            c1.UniqueName = "Field1";   
            c1.HeaderText = "Field1";   
            gridTest.MasterTableView.Columns.Add(c1);   
  
            GridBoundColumn c2 = new GridBoundColumn();   
            c2.DataField = "Field2";   
            c2.UniqueName = "Field2";   
            c2.HeaderText = "Field2";   
            gridTest.MasterTableView.Columns.Add(c2);   
  
            GridBoundColumn c3 = new GridBoundColumn();   
            c3.DataField = "Field3";   
            c3.UniqueName = "Field3";   
            c3.HeaderText = "Field3";   
            gridTest.MasterTableView.Columns.Add(c3);    
  
            pnl.Controls.Add(gridTest);   
  
        }   
  
        void gridCurrentWorkflows_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)   
        {   
  
            DataTable dt = new DataTable();   
            dt.Columns.Add("Col1");   
            DataRow rw = dt.NewRow();   
            rw["Col1"] = "";   
            dt.Rows.Add(rw);   
  
  
            e.DetailTableView.DataSource = dt;   
  
        }   
  
        void gridCurrentWorkflows_ItemCommand(object source, GridCommandEventArgs e)   
        {   
  
            switch (e.CommandName)   
            {   
                case "Button1":   
                case "Button2":   
                    {   
                        gridTest.Rebind();   
                        break;   
                    }   
            }   
        }   
  
        void gridCurrentWorkflows_NeedDataSource(object source, GridNeedDataSourceEventArgs e)   
        {   
            if (!e.IsFromDetailTable)   
            {   
                DataTable dt = new DataTable();   
                DataColumn dc1 = new DataColumn("Field1");   
                DataColumn dc2 = new DataColumn("Field2");   
                DataColumn dc3 = new DataColumn("Field3");   
                dt.Columns.Add(dc1);   
                dt.Columns.Add(dc2);   
                dt.Columns.Add(dc3);   
  
                DataRow dr1 = dt.NewRow();   
                dr1["Field1"] = "Value1";   
                dr1["Field2"] = "Value2";   
                dr1["Field3"] = "Value3";   
                dt.Rows.Add(dr1);   
  
                DataRow dr2 = dt.NewRow();   
                dr2["Field1"] = "Value1";   
                dr2["Field2"] = "Value2";   
                dr2["Field3"] = "Value3";   
                dt.Rows.Add(dr2);   
  
                DataRow dr3 = dt.NewRow();   
                dr3["Field1"] = "Value1";   
                dr3["Field2"] = "Value2";   
                dr3["Field3"] = "Value3";   
                dt.Rows.Add(dr3);   
  
                gridTest.DataSource = dt;   
            }   
        }  
 
 
    //Detail Column template   
    class DetailColumnTemplate : ITemplate   
    {   
  
        protected LinkButton btn1;   
        protected LinkButton btn2;   
  
        public void InstantiateIn(Control container)   
        {   
            GridDataItem itm = (GridDataItem)container.NamingContainer;   
  
            Panel pnlOuter = new Panel();   
            pnlOuter.ID = "pnlOuter";   
            pnlOuter.Width = Unit.Percentage(100);   
            btn2 = new LinkButton();   
            pnlOuter.Controls.Add(btn2);   
            btn2.CssClass = "FloatRight";   
            btn2.Text = "Button2";   
            btn2.CommandName = "Button2";   
  
            Label lbl = new Label();   
            pnlOuter.Controls.Add(lbl);   
            lbl.CssClass = "FloatRight";   
            lbl.Text = "  -  ";   
  
            btn1 = new LinkButton();   
            pnlOuter.Controls.Add(btn1);   
            btn1.CssClass = "FloatRight";   
            btn1.Text = "Button1";   
            btn1.CommandName = "Button1";   
  
            container.Controls.Add(pnlOuter);   
        }   
    }  
}