using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;

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

        RadGrid2.ItemCreated += new GridItemEventHandler(RadGrid2_ItemCreated);
    }

    void RadGrid2_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem item = e.Item as GridEditableItem;

            //Validate DropDownList.
            DropDownList dropDownList1 = item["GridDropDownColumn"].Controls[0] as DropDownList;
            GridDropDownColumnEditor editor = (GridDropDownColumnEditor)item.EditManager.GetColumnEditor("GridDropDownColumn");
            TableCell cell = (TableCell)(((Telerik.Web.UI.GridDropDownListColumnEditor)(editor))).DropDownListControl.Parent;
            RequiredFieldValidator validator = new RequiredFieldValidator();
            editor.ContainerControl.ID = "GridDropDownColumn";
            validator.ControlToValidate = dropDownList1.ID;
            validator.InitialValue = "0";
            validator.ErrorMessage = "This field is required!";
            cell.Controls.Add(validator);
           
            dropDownList1.AppendDataBoundItems = true;
            dropDownList1.Items.Add(new ListItem("--Select--", "0"));


            //Validate RadComboBox
            RadComboBox comboBox = item["City"].Controls[0] as RadComboBox;
            GridDropDownListColumnEditor editor1 = (GridDropDownListColumnEditor)item.EditManager.GetColumnEditor("City");

            RequiredFieldValidator validator1 = new RequiredFieldValidator();
            editor.ContainerControl.ID = "City";
            validator1.ControlToValidate = comboBox.ID;
            validator1.InitialValue = "--Select--";
            validator1.ErrorMessage = "This field is required!";
            cell.Controls.Add(validator1);

            comboBox.AppendDataBoundItems = true;
            comboBox.Items.Insert(0, new RadComboBoxItem("--Select--","0"));
           
        }
    }
}



