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

/// <summary>
/// Summary description for MyCompositeControl
/// </summary>
public class MyCompositeControl: CompositeControl
{
    private RadGrid rgFilterSelections;
    protected override void RecreateChildControls()
    {
        base.RecreateChildControls();
    }
    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        rgFilterSelections = new RadGrid();
        rgFilterSelections.ID = "rgFilterSelections";
        rgFilterSelections.Width = Unit.Percentage(98);
        rgFilterSelections.AutoGenerateColumns = false;
        rgFilterSelections.AllowSorting = false;
        rgFilterSelections.AllowPaging = true;
        rgFilterSelections.AllowCustomPaging = false;
        rgFilterSelections.PageSize = 200;
        rgFilterSelections.AllowMultiRowSelection = true;
        rgFilterSelections.ShowHeader = true;
        rgFilterSelections.PagerStyle.Mode = GridPagerMode.NumericPages;
        rgFilterSelections.MasterTableView.ClientDataKeyNames = new string[] { "id" };
        rgFilterSelections.MasterTableView.TableLayout = GridTableLayout.Fixed;
        rgFilterSelections.NeedDataSource += new GridNeedDataSourceEventHandler(rgFilterSelections_NeedDataSource);

        GridClientSelectColumn gcsc = new GridClientSelectColumn();
        gcsc.UniqueName = "ClientSelectColumn";
        gcsc.ItemStyle.Width = Unit.Pixel(20);

        GridBoundColumn gbcText = new GridBoundColumn();
        gbcText.DataField = "text";
        gbcText.UniqueName = "text";

        rgFilterSelections.MasterTableView.Columns.Add(gcsc);
        rgFilterSelections.MasterTableView.Columns.Add(gbcText);

        rgFilterSelections.ClientSettings.Selecting.AllowRowSelect = true;
        rgFilterSelections.ClientSettings.Selecting.EnableDragToSelectRows = true;
        rgFilterSelections.ClientSettings.Scrolling.AllowScroll = true;
        rgFilterSelections.ClientSettings.Scrolling.UseStaticHeaders = true;
        rgFilterSelections.ClientSettings.Scrolling.SaveScrollPosition = true;
        rgFilterSelections.ClientSettings.ClientEvents.OnCommand = "rgFilterSelections_Command";
        rgFilterSelections.ClientSettings.ClientEvents.OnRowDataBound = "rgFilterSelections_RowDataBound";
        
        this.Controls.Add(rgFilterSelections);
    }

    void rgFilterSelections_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        DataTable table = new DataTable();
        table.Columns.Add("id");
        table.Columns.Add("text");
        for (int i = 0; i < 10; i++)
        {
            table.Rows.Add(i, "text" + i.ToString());
        }
        rgFilterSelections.DataSource = table;
    }
}
