using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

public partial class WebUserControl : System.Web.UI.UserControl
{
    protected void Page_Init(object sender, System.EventArgs e)
    {
        DefineGridStructure();
    }
    private void DefineGridStructure()
    {
        RadGrid grid = new RadGrid();
        grid.ID = "RadGrid1";
        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" };
        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);
    }
}
