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

public partial class _Default : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        RadGrid1.NeedDataSource += new Telerik.Web.UI.GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
        RadGrid1.ItemDataBound += new Telerik.Web.UI.GridItemEventHandler(RadGrid1_ItemDataBound);
    }

    void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        DataTable table = new DataTable();
        table.Columns.Add("ID", typeof(int));
        table.Columns.Add("DivisionName");
        table.Columns.Add("LocationName");
        for (int i = 1; i < 8; i++)
        {
            table.Rows.Add(i, "DivisionName" + i.ToString(), "LocationName" + i.ToString());
        }

        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
        {
            RadComboBox dropdown = (e.Item as GridEditFormItem)["DivisionName"].FindControl("ddlDivisionName") as RadComboBox;
            dropdown.DataSource = table;
            dropdown.DataTextField = "DivisionName";
            dropdown.DataValueField = "ID";
            dropdown.DataBind();
            dropdown.SelectedIndex = Convert.ToInt32(((System.Data.DataRowView)((e.Item as GridEditFormItem).DataItem)).Row["ID"].ToString()) - 1;

            RadComboBox dropdown1 = (e.Item as GridEditFormItem)["LocationName"].FindControl("ddlLocationName") as RadComboBox;
            dropdown1.DataSource = table;
            dropdown1.DataTextField = "LocationName";
            dropdown1.DataValueField = "ID";
            dropdown1.DataBind();
            dropdown1.SelectedIndex = Convert.ToInt32(((System.Data.DataRowView)((e.Item as GridEditFormItem).DataItem)).Row["ID"].ToString()) - 1;
        }
    }

    void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        DataTable table = new DataTable();
        table.Columns.Add("ID", typeof(int));
        table.Columns.Add("DivisionName");
        table.Columns.Add("LocationName");
        for (int i = 1; i < 8; i++)
        {
            table.Rows.Add(i, "DivisionName" + i.ToString(), "LocationName" + i.ToString());
        }
        RadGrid1.DataSource = table;
    }
}
