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.Reflection;

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

    private void DefineGridStructure()
    {
        grid = new RadGrid();
        grid.ID = "grid";
        grid.DataSourceID = "AccessDataSource1";
        grid.Skin = "Vista";
        grid.Width = Unit.Percentage(100);
        grid.PageSize = 5;
        grid.AllowPaging = true;
        grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
        grid.AutoGenerateColumns = false;

        
        //Add Customers table
        grid.MasterTableView.PageSize = 15;
        //grid.MasterTableView.Width = Unit.Percentage(100);
        grid.MasterTableView.DataKeyNames = new string[] { "CustomerID" };
        grid.MasterTableView.DataSourceID = "AccessDataSource1";
        GridBoundColumn boundColumn = new GridBoundColumn();
        boundColumn.DataField = "CustomerID";
        boundColumn.HeaderText = "Customer ID";
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "ContactName";
        boundColumn.HeaderText = "Contact Name";
        grid.MasterTableView.Columns.Add(boundColumn);
        //Add Orders table
        GridTableView tableViewOrders = new GridTableView(grid);
        tableViewOrders.DataSourceID = "AccessDataSource2";
        //tableViewOrders.Width = Unit.Percentage(100);
        GridRelationFields relationFields = new GridRelationFields();
        relationFields.MasterKeyField = "CustomerID";
        relationFields.DetailKeyField = "CustomerID";
        tableViewOrders.ParentTableRelation.Add(relationFields);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "OrderID";
        boundColumn.HeaderText = "OrderID";
        tableViewOrders.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "OrderDate";
        boundColumn.HeaderText = "Date Ordered";
        tableViewOrders.Columns.Add(boundColumn);
        grid.MasterTableView.DetailTables.Add(tableViewOrders);
        // Add the grid to the placeholder
        this.PlaceHolder1.Controls.Add(grid);
    }
    protected void Page_Init(object source, System.EventArgs e)
    {
        DefineGridStructure();
    }
    protected void Button1_Click(object source, System.EventArgs e)
    {
        grid.ExportSettings.ExportOnlyData = true;
        grid.MasterTableView.ExportToPdf();
    }
}

