This is a migrated thread and some comments may be shown as answers.

Dropdown column in Grid

15 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 18 Sep 2013, 03:10 PM
How can i make the "DurationType" column in my code to a dropdown menu?

protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["GridData"] == null)
            {
                DataTable table = GetTable();
                Session.Add("GridData", table);
            }
            DefineGridStructure();
        }
// Code snipet to create the template in order to add the dropdown menu
public class MyTemplate : ITemplate
    {
        protected DropDownList dl;
        private string colname;

        public MyTemplate(string cName)
        {
            colname = cName;
        }

        public void InstantiateIn(System.Web.UI.Control container)
        {
            dl = new DropDownList();
            dl.ID = colname;
            dl.Items.Add(new ListItem("Hours", "Hours"));
            dl.Items.Add(new ListItem("Days", "Days"));
            dl.Items.Add(new ListItem("Weeks", "Weeks"));
            dl.Items.Add(new ListItem("Months", "Months"));
            container.Controls.Add(dl);
        }

        void LoadDefault_DataBinding(object sender, EventArgs e)
        {
            DropDownList dBox = (DropDownList)sender;
            GridDataItem container = (GridDataItem)dBox.NamingContainer;
        }

    } 
 




        private void DefineGridStructure()
        {
            RadGrid grid = new RadGrid();
            grid.ID = "RadGrid1";
            grid.NeedDataSource += new GridNeedDataSourceEventHandler(grid_NeedDataSource);
            grid.AutoGenerateEditColumn = true;
            grid.AutoGenerateDeleteColumn = true;
            grid.AllowAutomaticInserts = false;
            grid.Width = Unit.Percentage(100);
            grid.PageSize = 15;
            grid.AllowPaging = true;
            grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
            grid.AutoGenerateColumns = false;
            grid.MasterTableView.Width = Unit.Percentage(100);
            grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.TopAndBottom;
            grid.AllowAutomaticDeletes = false;
            grid.AllowAutomaticUpdates = false;
            grid.InsertCommand +=grid_InsertCommand;
            grid.MasterTableView.DataKeyNames = new string[] { "RowNumber" };
            GridBoundColumn boundColumn = new GridBoundColumn();
            boundColumn.DataField = "RowNumber";
            boundColumn.HeaderText = "RowNumber";
            boundColumn.ReadOnly = true;
            grid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "Size";
            boundColumn.HeaderText = "Size";
            grid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "Description";
            boundColumn.HeaderText = "Description";
            grid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "Quantity";
            boundColumn.HeaderText = "Quantity";
            grid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "Duration";
            boundColumn.HeaderText = "Duration";
            grid.MasterTableView.Columns.Add(boundColumn);

                // Added code snipet to create the drowpdown menu from an itemplate
                GridTemplateColumn objGridTemplateColumn = new GridTemplateColumn();
                objGridTemplateColumn.HeaderText = "DurationType";
                objGridTemplateColumn.UniqueName = "DurationType";
                objGridTemplateColumn.ItemTemplate = new MyTemplate("DurationType");
                grid.MasterTableView.Columns.Add(objGridTemplateColumn);           



            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "Amount";
            boundColumn.HeaderText = "Amount";
            grid.MasterTableView.Columns.Add(boundColumn);
            PlaceHolder1.Controls.Add(grid);
        }
 
        private void grid_InsertCommand(object sender, GridCommandEventArgs e)
        {
            // Looking to loop through the form so i can insert the values into the datatable
        }
 
 
 
 
 
        void grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            DataTable current = (DataTable)Session["GridData"];
            RadGrid grid = (RadGrid)sender;
            grid.DataSource = current;
 
        }
 
 
 
        static DataTable GetTable()
        {
            //
            // Here we create a DataTable with a few columns.
            //
            // Create Datatable to store all colums
            DataTable dt = new DataTable();
            DataRow dr = null;
            dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
            dt.Columns.Add(new DataColumn("Size", typeof(string)));
            dt.Columns.Add(new DataColumn("Description", typeof(string)));
            dt.Columns.Add(new DataColumn("Quantity", typeof(string)));
            dt.Columns.Add(new DataColumn("Unit", typeof(string)));
            dt.Columns.Add(new DataColumn("Duration", typeof(string)));
            dt.Columns.Add(new DataColumn("DurationType", typeof(string)));
            dt.Columns.Add(new DataColumn("Amount", typeof(string)));
            dr = dt.NewRow();
            dr["RowNumber"] = 1;
            dr["Size"] = string.Empty;
            dr["Description"] = string.Empty;
            dr["Quantity"] = string.Empty;
            dr["Unit"] = string.Empty;
            dr["Duration"] = string.Empty;
            dr["DurationType"] = string.Empty;
            dr["Amount"] = string.Empty;
            dt.Rows.Add(dr);
            return dt;
        }

15 Answers, 1 is accepted

Sort by
0
Brad
Top achievements
Rank 1
answered on 18 Sep 2013, 05:48 PM
I modified the code and added the section to create a template with a drop down and added the dropdown to DurationType column. Now when i load the page i see the dropdown, but i can't figure out how to get the selected value from here and if i update the code, i want to make sure when the dropdown loads, it loads with the right item selected. Also how can i make the actual dropdown only load in the insert or edit template, and when it displays the actual grid just to show it as text?
0
Brad
Top achievements
Rank 1
answered on 19 Sep 2013, 09:28 PM
Any help please, I'm going crazy trying to get this to work.
0
Princy
Top achievements
Rank 1
answered on 20 Sep 2013, 12:13 PM
Hi Brad,

Please try the following code snippet.

C#:
protected void Page_Init(object sender, EventArgs e)
{
    RadGrid RadGrid1;
    RadGrid1 = new RadGrid();
    RadGrid1.DataSourceID = "SqlDataSource1";
    RadGrid1.MasterTableView.DataKeyNames = new string[] { "Orderid" }; 
    RadGrid1.AllowPaging = true;
    RadGrid1.AutoGenerateColumns = false;
    RadGrid1.ShowHeader = true;
    RadGrid1.AutoGenerateEditColumn = true;  
    RadGrid1.ItemDataBound+=new GridItemEventHandler(RadGrid1_ItemDataBound);
 
    GridBoundColumn boundColumn1;
    boundColumn1 = new GridBoundColumn();      
    boundColumn1.DataField = "orderid";
    boundColumn1.HeaderText = "orderid";
    RadGrid1.MasterTableView.Columns.Add(boundColumn1);  
 
    string templateColumnName = "employeeid";  
    GridTemplateColumn templateColumn = new GridTemplateColumn();
    templateColumn.ItemTemplate = new MyTemplate(templateColumnName);
    templateColumn.EditItemTemplate = new MyEditTemplate();  //Create EditItemTemplate
    RadGrid1.MasterTableView.Columns.Add(templateColumn); 
    templateColumn.HeaderText = templateColumnName;
    templateColumn.DataField = "EmployeeID";
    PlaceHolder1.Controls.Add(RadGrid1);
}
public class MyTemplate : ITemplate
{
    private string colname;
    protected Label lControl;
    public MyTemplate(string cName)
    {
        colname = cName;          
    }
    public void InstantiateIn(System.Web.UI.Control container)
    {
        lControl = new Label();
        lControl.ID = "lControl";
        lControl.DataBinding += new EventHandler(lControl_DataBinding);
        container.Controls.Add(lControl);
    }
 
    public void lControl_DataBinding(object sender, EventArgs e)
    {
        Label l = (Label)sender;
        GridDataItem container = (GridDataItem)l.NamingContainer;
        l.Text = ((DataRowView)container.DataItem)[colname].ToString() + "<br />";
    }
}
 
public class MyEditTemplate : IBindableTemplate
    {
       public void InstantiateIn(Control container)
       {
           GridEditFormItem item = ((GridEditFormItem)(container.NamingContainer)); 
           DropDownList drop = new DropDownList();
           drop.ID = "dropdownlist1";
           container.Controls.Add(drop);       
       }
       public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container)
       {
           OrderedDictionary od = new OrderedDictionary();
           od.Add("OrderID", ((DropDownList)(((GridEditFormItem)(container)).FindControl("dropdownlist1"))).DataValueField);
           return od;
       
    }
 
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
        {
            GridEditFormItem editItem = (GridEditFormItem)e.Item;
            DropDownList ddl = (DropDownList)editItem.FindControl("dropdownlist1");
            ddl.DataSourceID = "SqlDataSource1";
            ddl.DataTextField = "Employeeid";
            ddl.DataValueField = "Employeeid";
            ddl.SelectedIndex = editItem.ItemIndex;
        }
    }

Thanks,
Princy
0
Brad
Top achievements
Rank 1
answered on 20 Sep 2013, 01:59 PM
Princy,

Thank you very much for your response, i just tried to implement that code into my code but as soon as i click edit on the grid, i get the following error:

{"Unable to cast object of type 'Telerik.Web.UI.GridDataItem' to type 'Telerik.Web.UI.GridEditFormItem'."}

and its for this line of code:

 
public class MyEditTemplate : IBindableTemplate
    {
        public void InstantiateIn(Control container)
        {
            GridEditFormItem item = ((GridEditFormItem)(container.NamingContainer)); // This is the line causing that error
            DropDownList drop = new DropDownList();
            drop.ID = "dropdownlist1";
            container.Controls.Add(drop);
        }
        public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container)
        {
            OrderedDictionary od = new OrderedDictionary();
            od.Add("OrderID", ((DropDownList)(((GridEditFormItem)(container)).FindControl("dropdownlist1"))).DataValueField);
            return od;
        }
    }
0
Brad
Top achievements
Rank 1
answered on 20 Sep 2013, 02:20 PM
I have modified the code for the dropdown box, i see the dropdown box when i click edit, but when i choose a dropdown item like weeks, and click update, the grid just shows me "DurationType" in the text instead of "weeks".  Can you please help me fix this? I'm really trying to get this to work.


public partial class Default5 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["GridData"] == null)
        {
            DataTable table = GetTable();
            Session.Add("GridData", table);
        }
        DefineGridStructure();
    }
 
 
    public class MyTemplate : ITemplate
    {
        private string colname;
        protected Label lControl;
        public MyTemplate(string cName)
        {
            colname = cName;
        }
        public void InstantiateIn(System.Web.UI.Control container)
        {
            lControl = new Label();
            lControl.ID = "lControl";
            lControl.DataBinding += new EventHandler(lControl_DataBinding);
            container.Controls.Add(lControl);
        }
 
        public void lControl_DataBinding(object sender, EventArgs e)
        {
            Label l = (Label)sender;
            GridDataItem container = (GridDataItem)l.NamingContainer;
            l.Text = ((DataRowView)container.DataItem)[colname].ToString() + "<br />";
        }
    }
 
 
    public class MyEditTemplate : IBindableTemplate
    {
        public void InstantiateIn(Control container)
        {
            GridDataItem item = ((GridDataItem)(container.NamingContainer));
            DropDownList drop = new DropDownList();
            drop.ID = "dropdownlist1";
            drop.DataSource = (DataTable)GetTableForDropDown();
            drop.DataTextField = "DurationType";
            drop.DataValueField = "DurationType";
             
            container.Controls.Add(drop);
        }
        public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container)
        {
            OrderedDictionary od = new OrderedDictionary();
            od.Add("DurationType", ((DropDownList)(((GridDataItem)(container)).FindControl("dropdownlist1"))).DataValueField);
            return od;
        }
    }
 
 
 
    protected void grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
        {
            GridEditFormItem editItem = (GridEditFormItem)e.Item;
            DropDownList ddl = (DropDownList)editItem.FindControl("dropdownlist1");
            ddl.DataSource = (DataTable)GetTableForDropDown();
            ddl.DataTextField = "DurationType";
            ddl.DataValueField = "DurationType";
            ddl.SelectedIndex = editItem.ItemIndex;
        }
    }
 
 
 
 
    private void DefineGridStructure()
    {
 
 
        RadGrid grid = new RadGrid();
        grid.ID = "RadGrid1";
        grid.NeedDataSource += new GridNeedDataSourceEventHandler(grid_NeedDataSource);
        grid.AutoGenerateEditColumn = true;
        grid.AutoGenerateDeleteColumn = true;
        grid.AllowAutomaticInserts = false;
        grid.Width = Unit.Percentage(100);
        grid.PageSize = 15;
        grid.AllowPaging = true;
        grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
        grid.AutoGenerateColumns = false;
        grid.MasterTableView.Width = Unit.Percentage(100);
        grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.TopAndBottom;
        grid.AllowAutomaticDeletes = false;
        grid.AllowAutomaticUpdates = false;
        grid.ItemDataBound+=new GridItemEventHandler(grid_ItemDataBound);
        grid.InsertCommand += grid_InsertCommand;
        grid.DeleteCommand += grid_DeleteCommand;
        grid.UpdateCommand +=grid_UpdateCommand;
        grid.MasterTableView.DataKeyNames = new string[] { "RowNumber" };
        GridBoundColumn boundColumn = new GridBoundColumn();
        boundColumn.DataField = "RowNumber";
        boundColumn.HeaderText = "RowNumber";
        boundColumn.ReadOnly = true;
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Size";
        boundColumn.HeaderText = "Size";
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Description";
        boundColumn.HeaderText = "Description";
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Quantity";
        boundColumn.HeaderText = "Quantity";
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Duration";
        boundColumn.HeaderText = "Duration";
        grid.MasterTableView.Columns.Add(boundColumn);
 
        GridTemplateColumn objGridTemplateColumn = new GridTemplateColumn();
        objGridTemplateColumn.HeaderText = "DurationType";
        objGridTemplateColumn.DataField = "DurationType";
        objGridTemplateColumn.ItemTemplate = new MyTemplate("DurationType");
        objGridTemplateColumn.EditItemTemplate = new MyEditTemplate();
        grid.MasterTableView.Columns.Add(objGridTemplateColumn);
 
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Amount";
        boundColumn.HeaderText = "Amount";
        grid.MasterTableView.Columns.Add(boundColumn);
        grid.MasterTableView.EditMode = GridEditMode.InPlace;
        PlaceHolder1.Controls.Add(grid);
    }
 
  
    private void grid_UpdateCommand(object sender, GridCommandEventArgs e)
    {
 
 
        GridEditableItem editItem = e.Item as GridEditableItem;
        Hashtable newValues = new Hashtable();
        e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editItem);
     
 
 
        DataTable dtCurrentTable = (DataTable)Session["GridData"];
        foreach (DictionaryEntry entry in newValues)
        {
            dtCurrentTable.Rows[e.Item.ItemIndex][entry.Key.ToString()] = entry.Value;
        }
    }
 
    private void grid_DeleteCommand(object sender, GridCommandEventArgs e)
    {
        GridDataItem item = e.Item as GridDataItem;
        DataTable dt = (DataTable)Session["GridData"];
        dt.Rows.Remove(dt.Rows[item.ItemIndex]);
        ResetRowID(dt);
    }
 
    private void grid_InsertCommand(object sender, GridCommandEventArgs e)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        GridEditManager editMan = editedItem.EditManager;
 
        //Set new values
        Hashtable newValues = new Hashtable();
        //The GridTableView will fill the values from all editable columns in the hash
        e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
 
        DataTable dtCurrentTable = (DataTable)Session["GridData"];
        DataRow dr = null;
        int count = dtCurrentTable.Rows.Count;
        count++;
 
        dr = dtCurrentTable.NewRow();
        dr["RowNumber"] = count;
 
            foreach (DictionaryEntry entry in newValues)
            {
                
               dr[entry.Key.ToString()] = entry.Value;
                
            }
            dtCurrentTable.Rows.Add(dr);
           
    }
 
     
 
 
 
    void grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        DataTable current = (DataTable)Session["GridData"];
        RadGrid grid = (RadGrid)sender;
        grid.DataSource = current;
         
 
    }
 
 
 
    static DataTable GetTable()
    {
        //
        // Here we create a DataTable with a few columns.
        //
        // Create Datatable to store all colums
        DataTable dt = new DataTable();
        DataRow dr = null;
        dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
        dt.Columns.Add(new DataColumn("Size", typeof(string)));
        dt.Columns.Add(new DataColumn("Description", typeof(string)));
        dt.Columns.Add(new DataColumn("Quantity", typeof(string)));
        dt.Columns.Add(new DataColumn("Unit", typeof(string)));
        dt.Columns.Add(new DataColumn("Duration", typeof(string)));
        dt.Columns.Add(new DataColumn("DurationType", typeof(string)));
        dt.Columns.Add(new DataColumn("Amount", typeof(string)));
        dr = dt.NewRow();
        dr["RowNumber"] = 1;
        dr["Size"] = string.Empty;
        dr["Description"] = string.Empty;
        dr["Quantity"] = string.Empty;
        dr["Unit"] = string.Empty;
        dr["Duration"] = string.Empty;
        dr["DurationType"] = string.Empty;
        dr["Amount"] = string.Empty;
        dt.Rows.Add(dr);
 
        dr = dt.NewRow();
        dr["RowNumber"] = 2;
        dr["Size"] = string.Empty;
        dr["Description"] = string.Empty;
        dr["Quantity"] = string.Empty;
        dr["Unit"] = string.Empty;
        dr["Duration"] = string.Empty;
        dr["DurationType"] = string.Empty;
        dr["Amount"] = string.Empty;
        dt.Rows.Add(dr);
 
        dr = dt.NewRow();
        dr["RowNumber"] = 3;
        dr["Size"] = string.Empty;
        dr["Description"] = string.Empty;
        dr["Quantity"] = string.Empty;
        dr["Unit"] = string.Empty;
        dr["Duration"] = string.Empty;
        dr["DurationType"] = string.Empty;
        dr["Amount"] = string.Empty;
        dt.Rows.Add(dr);
 
        dr = dt.NewRow();
        dr["RowNumber"] = 4;
        dr["Size"] = string.Empty;
        dr["Description"] = string.Empty;
        dr["Quantity"] = string.Empty;
        dr["Unit"] = string.Empty;
        dr["Duration"] = string.Empty;
        dr["DurationType"] = string.Empty;
        dr["Amount"] = string.Empty;
        dt.Rows.Add(dr);
 
        dr = dt.NewRow();
        dr["RowNumber"] = 5;
        dr["Size"] = string.Empty;
        dr["Description"] = string.Empty;
        dr["Quantity"] = string.Empty;
        dr["Unit"] = string.Empty;
        dr["Duration"] = string.Empty;
        dr["DurationType"] = string.Empty;
        dr["Amount"] = string.Empty;
        dt.Rows.Add(dr);
        return dt;
    }
 
 
 
    static DataTable GetTableForDropDown()
    {
        //
        // Here we create a DataTable with a few columns.
        //
        // Create Datatable to store all colums
        DataTable dt = new DataTable();
        DataRow dr = null;
        dt.Columns.Add(new DataColumn("DurationType", typeof(string)));
         
        dr = dt.NewRow();
        dr["DurationType"] = "Hours";
        dt.Rows.Add(dr);
 
        dr = dt.NewRow();
        dr["DurationType"] = "Days";
        dt.Rows.Add(dr);
 
        dr = dt.NewRow();
        dr["DurationType"] = "Weeks";
        dt.Rows.Add(dr);
 
        dr = dt.NewRow();
        dr["DurationType"] = "Months";
        dt.Rows.Add(dr);
        return dt;
    }
 
 
 
    private void ResetRowID(DataTable dt)
    {
        int rowNumber = 1;
 
        if (dt.Rows.Count > 0)
        {
            foreach (DataRow row in dt.Rows)
            {
                row[0] = rowNumber;
                rowNumber++;
            }
        }
    }
 
}
0
Brad
Top achievements
Rank 1
answered on 20 Sep 2013, 08:19 PM
I don't mean to be such a pain, but my boss wants to see a working model of what he is going to want our team to program, and he we are all trying to tell him that he needs to purchase telerik. But until he see's this working and see's how good the support is, he doesn't want to purchase anything. He said that if we can have a working model up and running by monday morning, he will let us purchase telerik. Please help, we really want to be able to purchase your products.
0
Princy
Top achievements
Rank 1
answered on 21 Sep 2013, 08:47 AM
Hi Brad,

I have modified the code,please try the below code snippet.ExtractValuesFromItem doesn't work with TemplateColumns,that's why the values weren't updated.

C#:
protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["GridData"] == null)
        {
            DataTable table = GetTable();
            Session.Add("GridData", table);
        }
        DefineGridStructure();
    }
  
    public class MyTemplate : ITemplate
    {
        private string colname;
        protected Label lControl;
        public MyTemplate(string cName)
        {
            colname = cName;
        }
        public void InstantiateIn(System.Web.UI.Control container)
        {
            lControl = new Label();
            lControl.ID = "lControl";
            lControl.DataBinding += new EventHandler(lControl_DataBinding);
            container.Controls.Add(lControl);
        }
  
        public void lControl_DataBinding(object sender, EventArgs e)
        {
            Label l = (Label)sender;
            GridDataItem container = (GridDataItem)l.NamingContainer;
            l.Text = ((DataRowView)container.DataItem)[colname].ToString() + "<br />";
        }
    }
  
  
    public class MyEditTemplate : IBindableTemplate
    {
        public void InstantiateIn(Control container)
        {
            GridDataItem item = ((GridDataItem)(container.NamingContainer));
            DropDownList drop = new DropDownList();
            drop.ID = "dropdownlist1";
            drop.DataSource = (DataTable)GetTableForDropDown();
            drop.DataTextField = "DurationType";
            drop.DataValueField = "DurationType";
              
            container.Controls.Add(drop);
        }
        public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container)
        {
            OrderedDictionary od = new OrderedDictionary();
            od.Add("DurationType", ((DropDownList)(((GridDataItem)(container)).FindControl("dropdownlist1"))).DataValueField);
            return od;
        }
    }

    protected void grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
        {
            GridEditFormItem editItem = (GridEditFormItem)e.Item;
            DropDownList ddl = (DropDownList)editItem.FindControl("dropdownlist1");
            ddl.DataSource = (DataTable)GetTableForDropDown();
            ddl.DataTextField = "DurationType";
            ddl.DataValueField = "DurationType";
            ddl.SelectedIndex = editItem.ItemIndex;
        }
    } 

    private void DefineGridStructure()
    {
        RadGrid grid = new RadGrid();
        grid.ID = "RadGrid1";
        grid.NeedDataSource += new GridNeedDataSourceEventHandler(grid_NeedDataSource);
        grid.AutoGenerateEditColumn = true;
        grid.AutoGenerateDeleteColumn = true;
        grid.AllowAutomaticInserts = false;
        grid.Width = Unit.Percentage(100);
        grid.PageSize = 15;
        grid.AllowPaging = true;
        grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
        grid.AutoGenerateColumns = false;
        grid.MasterTableView.Width = Unit.Percentage(100);
        grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.TopAndBottom;
        grid.AllowAutomaticDeletes = false;
        grid.AllowAutomaticUpdates = false;
        grid.ItemDataBound+=new GridItemEventHandler(grid_ItemDataBound);
        grid.InsertCommand += grid_InsertCommand;
        grid.DeleteCommand += grid_DeleteCommand;
        grid.UpdateCommand +=grid_UpdateCommand;
        grid.MasterTableView.DataKeyNames = new string[] { "RowNumber" };
        GridBoundColumn boundColumn = new GridBoundColumn();
        boundColumn.DataField = "RowNumber";
        boundColumn.HeaderText = "RowNumber";
        boundColumn.ReadOnly = true;
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Size";
        boundColumn.HeaderText = "Size";
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Description";
        boundColumn.HeaderText = "Description";
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Quantity";
        boundColumn.HeaderText = "Quantity";
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Duration";
        boundColumn.HeaderText = "Duration";
        grid.MasterTableView.Columns.Add(boundColumn);
  
        GridTemplateColumn objGridTemplateColumn = new GridTemplateColumn();
        objGridTemplateColumn.HeaderText = "DurationType";
        objGridTemplateColumn.DataField = "DurationType";
        objGridTemplateColumn.ItemTemplate = new MyTemplate("DurationType");
        objGridTemplateColumn.EditItemTemplate = new MyEditTemplate();
        grid.MasterTableView.Columns.Add(objGridTemplateColumn);
  
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Amount";
        boundColumn.HeaderText = "Amount";
        grid.MasterTableView.Columns.Add(boundColumn);
        grid.MasterTableView.EditMode = GridEditMode.InPlace;
        PlaceHolder1.Controls.Add(grid);
    }
  
   
    private void grid_UpdateCommand(object sender, GridCommandEventArgs e)
 {  
    GridEditableItem editItem = e.Item as GridEditableItem;
    Hashtable newValues = new Hashtable();
    newValues["RowNumber"] = (editItem["RowNumber"].Controls[0] as TextBox).Text;
    newValues["Size"] = (editItem["Size"].Controls[0] as TextBox).Text;
    newValues["Description"] = (editItem["Description"].Controls[0] as TextBox).Text;
    newValues["Quantity"] = (editItem["Quantity"].Controls[0] as TextBox).Text;
    newValues["Duration"] = (editItem["Duration"].Controls[0] as TextBox).Text;
    newValues["DurationType"] = (editItem.FindControl("dropdownlist1") as DropDownList).SelectedValue;
    newValues["Amount"] = (editItem["Amount"].Controls[0] as TextBox).Text;
    DataTable dtCurrentTable = (DataTable)Session["GridData"];
    foreach (DictionaryEntry entry in newValues)
    {
        dtCurrentTable.Rows[e.Item.ItemIndex][entry.Key.ToString()] = entry.Value;
    }
}
     
  
    private void grid_DeleteCommand(object sender, GridCommandEventArgs e)
    {
        GridDataItem item = e.Item as GridDataItem;
        DataTable dt = (DataTable)Session["GridData"];
        dt.Rows.Remove(dt.Rows[item.ItemIndex]);
        ResetRowID(dt);
    }
 
    private void grid_InsertCommand(object sender, GridCommandEventArgs e)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        GridEditManager editMan = editedItem.EditManager;
        //Set new values
        Hashtable newValues = new Hashtable();
        //The GridTableView will fill the values from all editable columns in the hash
        
        DataTable dtCurrentTable = (DataTable)Session["GridData"];
        DataRow dr = null;
        int count = dtCurrentTable.Rows.Count;
        count++;
        dr = dtCurrentTable.NewRow();
        dr["RowNumber"] = count;
        newValues["RowNumber"] = count;
        newValues["Size"] = (editedItem["Size"].Controls[0] as TextBox).Text;
        newValues["Description"] = (editedItem["Description"].Controls[0] as TextBox).Text;
        newValues["Quantity"] = (editedItem["Quantity"].Controls[0] as TextBox).Text;
        newValues["Duration"] = (editedItem["Duration"].Controls[0] as TextBox).Text;
        newValues["DurationType"] = (editedItem.FindControl("dropdownlist1") as DropDownList).SelectedValue;
        newValues["Amount"] = (editedItem["Amount"].Controls[0] as TextBox).Text;
        foreach (DictionaryEntry entry in newValues)
        {
            dr[entry.Key.ToString()] = entry.Value;
        }
        dtCurrentTable.Rows.Add(dr);
    }

    void grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        DataTable current = (DataTable)Session["GridData"];
        RadGrid grid = (RadGrid)sender;
        grid.DataSource = current;
          
  
    }

    static DataTable GetTable()
    {
        //
        // Here we create a DataTable with a few columns.
        //
        // Create Datatable to store all colums
        DataTable dt = new DataTable();
        DataRow dr = null;
        dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
        dt.Columns.Add(new DataColumn("Size", typeof(string)));
        dt.Columns.Add(new DataColumn("Description", typeof(string)));
        dt.Columns.Add(new DataColumn("Quantity", typeof(string)));
        dt.Columns.Add(new DataColumn("Unit", typeof(string)));
        dt.Columns.Add(new DataColumn("Duration", typeof(string)));
        dt.Columns.Add(new DataColumn("DurationType", typeof(string)));
        dt.Columns.Add(new DataColumn("Amount", typeof(string)));
        dr = dt.NewRow();
        dr["RowNumber"] = 1;
        dr["Size"] = string.Empty;
        dr["Description"] = string.Empty;
        dr["Quantity"] = string.Empty;
        dr["Unit"] = string.Empty;
        dr["Duration"] = string.Empty;
        dr["DurationType"] = string.Empty;
        dr["Amount"] = string.Empty;
        dt.Rows.Add(dr);
  
        dr = dt.NewRow();
        dr["RowNumber"] = 2;
        dr["Size"] = string.Empty;
        dr["Description"] = string.Empty;
        dr["Quantity"] = string.Empty;
        dr["Unit"] = string.Empty;
        dr["Duration"] = string.Empty;
        dr["DurationType"] = string.Empty;
        dr["Amount"] = string.Empty;
        dt.Rows.Add(dr);
  
        dr = dt.NewRow();
        dr["RowNumber"] = 3;
        dr["Size"] = string.Empty;
        dr["Description"] = string.Empty;
        dr["Quantity"] = string.Empty;
        dr["Unit"] = string.Empty;
        dr["Duration"] = string.Empty;
        dr["DurationType"] = string.Empty;
        dr["Amount"] = string.Empty;
        dt.Rows.Add(dr);
  
        dr = dt.NewRow();
        dr["RowNumber"] = 4;
        dr["Size"] = string.Empty;
        dr["Description"] = string.Empty;
        dr["Quantity"] = string.Empty;
        dr["Unit"] = string.Empty;
        dr["Duration"] = string.Empty;
        dr["DurationType"] = string.Empty;
        dr["Amount"] = string.Empty;
        dt.Rows.Add(dr);
  
        dr = dt.NewRow();
        dr["RowNumber"] = 5;
        dr["Size"] = string.Empty;
        dr["Description"] = string.Empty;
        dr["Quantity"] = string.Empty;
        dr["Unit"] = string.Empty;
        dr["Duration"] = string.Empty;
        dr["DurationType"] = string.Empty;
        dr["Amount"] = string.Empty;
        dt.Rows.Add(dr);
        return dt;
    }

    static DataTable GetTableForDropDown()
    {
        //
        // Here we create a DataTable with a few columns.
        //
        // Create Datatable to store all colums
        DataTable dt = new DataTable();
        DataRow dr = null;
        dt.Columns.Add(new DataColumn("DurationType", typeof(string)));
          
        dr = dt.NewRow();
        dr["DurationType"] = "Hours";
        dt.Rows.Add(dr);
  
        dr = dt.NewRow();
        dr["DurationType"] = "Days";
        dt.Rows.Add(dr);
  
        dr = dt.NewRow();
        dr["DurationType"] = "Weeks";
        dt.Rows.Add(dr);
  
        dr = dt.NewRow();
        dr["DurationType"] = "Months";
        dt.Rows.Add(dr);
        return dt;
    } 

    private void ResetRowID(DataTable dt)
    {
        int rowNumber = 1;
  
        if (dt.Rows.Count > 0)
        {
            foreach (DataRow row in dt.Rows)
            {
                row[0] = rowNumber;
                rowNumber++;
            }
        }
    }

Thanks,
Princy
0
Brad
Top achievements
Rank 1
answered on 21 Sep 2013, 02:02 PM
Wow, that's perfect, exactly what i was looking for, thank you so much!!!
0
Brad
Top achievements
Rank 1
answered on 23 Sep 2013, 11:39 PM
I was just testing everything and noticed something, that when i click edit and go into the edit form, the actually value that should be selected isn't, its always set to the first option, its doesn't look to see what the actual value is and makes the selected index that value. Can you please assist with this?
0
Princy
Top achievements
Rank 1
answered on 24 Sep 2013, 04:20 AM
Hi Brad,

Please add the following code to your ItemDataBound event to get the selected value.

C#:
protected void grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {
       if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
       {
        GridEditFormItem editItem = (GridEditFormItem)e.Item;
        DropDownList ddl = (DropDownList)editItem.FindControl("dropdownlist1");
        ddl.DataSource = (DataTable)GetTableForDropDown();
        ddl.DataTextField = "DurationType";
        ddl.DataValueField = "DurationType";         
        ddl.SelectedIndex = editItem.ItemIndex;
        ddl.SelectedValue = DataBinder.Eval(editItem.DataItem, "DurationType").ToString(); // To get the selected value          
       }
   }

Thanks,
Princy
0
Brad
Top achievements
Rank 1
answered on 24 Sep 2013, 04:32 AM
Thank you for your response, but it does the same thing. When i click edit, instead of the dropdown menu starting with the "selected" value it just starts at the beginning.
0
Accepted
Princy
Top achievements
Rank 1
answered on 24 Sep 2013, 05:10 AM
Hi Brad,

Please try the below code snippet,I have modified the code and it works fine at my end.

C#:
protected void Page_Load(object sender, EventArgs e)
   {
       if (Session["GridData"] == null)
       {
           DataTable table = GetTable();
           Session.Add("GridData", table);
       }
       DefineGridStructure();
   }
 
   public class MyTemplate : ITemplate
   {
       private string colname;
       protected Label lControl;
       public MyTemplate(string cName)
       {
           colname = cName;
       }
       public void InstantiateIn(System.Web.UI.Control container)
       {
           lControl = new Label();
           lControl.ID = "lControl";
           lControl.DataBinding += new EventHandler(lControl_DataBinding);
           container.Controls.Add(lControl);
       }
 
       public void lControl_DataBinding(object sender, EventArgs e)
       {
           Label l = (Label)sender;
           GridDataItem container = (GridDataItem)l.NamingContainer;
           l.Text = ((DataRowView)container.DataItem)[colname].ToString() + "<br />";
       }
   }
 
 
   public class MyEditTemplate : IBindableTemplate
   {
       public void InstantiateIn(Control container)
       {
           GridEditableItem item = ((GridEditableItem)(container.NamingContainer));
           DropDownList drop = new DropDownList();
           drop.ID = "dropdownlist1";
           drop.DataSource = (DataTable)GetTableForDropDown();
           drop.DataTextField = "DurationType";
           drop.DataValueField = "DurationType";
 
           container.Controls.Add(drop);
       }
       public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container)
       {
           OrderedDictionary od = new OrderedDictionary();
           od.Add("DurationType", ((DropDownList)(((GridEditableItem)(container)).FindControl("dropdownlist1"))).DataValueField);
           return od;
       }
   }
 
   protected void grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {
       if (e.Item is GridEditableItem && e.Item.IsInEditMode)
       {
           GridEditableItem editItem = (GridEditableItem)e.Item;
           DropDownList ddl = (DropDownList)editItem.FindControl("dropdownlist1");
           ddl.DataSource = (DataTable)GetTableForDropDown();
           ddl.DataTextField = "DurationType";
           ddl.DataValueField = "DurationType";      
           ddl.SelectedValue = DataBinder.Eval(editItem.DataItem, "DurationType").ToString();         
       }
   }
 
   private void DefineGridStructure()
   {
       RadGrid grid = new RadGrid();
       grid.ID = "RadGrid1";
       grid.NeedDataSource += new GridNeedDataSourceEventHandler(grid_NeedDataSource);
       grid.AutoGenerateEditColumn = true;
       grid.AutoGenerateDeleteColumn = true;
       grid.AllowAutomaticInserts = false;
       grid.Width = Unit.Percentage(100);
       grid.PageSize = 15;
       grid.AllowPaging = true;
       grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
       grid.AutoGenerateColumns = false;
       grid.MasterTableView.Width = Unit.Percentage(100);
       grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.TopAndBottom;
       grid.AllowAutomaticDeletes = false;
       grid.AllowAutomaticUpdates = false;
       grid.ItemDataBound += new GridItemEventHandler(grid_ItemDataBound);
       grid.InsertCommand += grid_InsertCommand;
       grid.DeleteCommand += grid_DeleteCommand;
       grid.UpdateCommand += grid_UpdateCommand;
       grid.MasterTableView.DataKeyNames = new string[] { "RowNumber" };
       GridBoundColumn boundColumn = new GridBoundColumn();
       boundColumn.DataField = "RowNumber";
       boundColumn.HeaderText = "RowNumber";
       boundColumn.ReadOnly = true;
       grid.MasterTableView.Columns.Add(boundColumn);
       boundColumn = new GridBoundColumn();
       boundColumn.DataField = "Size";
       boundColumn.HeaderText = "Size";
       grid.MasterTableView.Columns.Add(boundColumn);
       boundColumn = new GridBoundColumn();
       boundColumn.DataField = "Description";
       boundColumn.HeaderText = "Description";
       grid.MasterTableView.Columns.Add(boundColumn);
       boundColumn = new GridBoundColumn();
       boundColumn.DataField = "Quantity";
       boundColumn.HeaderText = "Quantity";
       grid.MasterTableView.Columns.Add(boundColumn);
       boundColumn = new GridBoundColumn();
       boundColumn.DataField = "Duration";
       boundColumn.HeaderText = "Duration";
       grid.MasterTableView.Columns.Add(boundColumn);
 
       GridTemplateColumn objGridTemplateColumn = new GridTemplateColumn();
       objGridTemplateColumn.HeaderText = "DurationType";
       objGridTemplateColumn.DataField = "DurationType";
       objGridTemplateColumn.ItemTemplate = new MyTemplate("DurationType");
       objGridTemplateColumn.EditItemTemplate = new MyEditTemplate();
       grid.MasterTableView.Columns.Add(objGridTemplateColumn);
 
       boundColumn = new GridBoundColumn();
       boundColumn.DataField = "Amount";
       boundColumn.HeaderText = "Amount";
       grid.MasterTableView.Columns.Add(boundColumn);
       grid.MasterTableView.EditMode = GridEditMode.InPlace;
       PlaceHolder1.Controls.Add(grid);
   }
 
 
   private void grid_UpdateCommand(object sender, GridCommandEventArgs e)
   {
       GridEditableItem editItem = e.Item as GridEditableItem;
       Hashtable newValues = new Hashtable();
       newValues["RowNumber"] = (editItem["RowNumber"].Controls[0] as TextBox).Text;
       newValues["Size"] = (editItem["Size"].Controls[0] as TextBox).Text;
       newValues["Description"] = (editItem["Description"].Controls[0] as TextBox).Text;
       newValues["Quantity"] = (editItem["Quantity"].Controls[0] as TextBox).Text;
       newValues["Duration"] = (editItem["Duration"].Controls[0] as TextBox).Text;
       newValues["DurationType"] = (editItem.FindControl("dropdownlist1") as DropDownList).SelectedValue;
       newValues["Amount"] = (editItem["Amount"].Controls[0] as TextBox).Text;
       DataTable dtCurrentTable = (DataTable)Session["GridData"];
       foreach (DictionaryEntry entry in newValues)
       {
           dtCurrentTable.Rows[e.Item.ItemIndex][entry.Key.ToString()] = entry.Value;
       }
   }
 
 
   private void grid_DeleteCommand(object sender, GridCommandEventArgs e)
   {
       GridDataItem item = e.Item as GridDataItem;
       DataTable dt = (DataTable)Session["GridData"];
       dt.Rows.Remove(dt.Rows[item.ItemIndex]);
       ResetRowID(dt);
   }
 
   private void grid_InsertCommand(object sender, GridCommandEventArgs e)
   {
       GridEditableItem editedItem = e.Item as GridEditableItem;
       GridEditManager editMan = editedItem.EditManager;
       //Set new values
       Hashtable newValues = new Hashtable();
       //The GridTableView will fill the values from all editable columns in the hash
 
       DataTable dtCurrentTable = (DataTable)Session["GridData"];
       DataRow dr = null;
       int count = dtCurrentTable.Rows.Count;
       count++;
       dr = dtCurrentTable.NewRow();
       dr["RowNumber"] = count;
       newValues["RowNumber"] = count;
       newValues["Size"] = (editedItem["Size"].Controls[0] as TextBox).Text;
       newValues["Description"] = (editedItem["Description"].Controls[0] as TextBox).Text;
       newValues["Quantity"] = (editedItem["Quantity"].Controls[0] as TextBox).Text;
       newValues["Duration"] = (editedItem["Duration"].Controls[0] as TextBox).Text;
       newValues["DurationType"] = (editedItem.FindControl("dropdownlist1") as DropDownList).SelectedValue;
       newValues["Amount"] = (editedItem["Amount"].Controls[0] as TextBox).Text;
       foreach (DictionaryEntry entry in newValues)
       {
           dr[entry.Key.ToString()] = entry.Value;
       }
       dtCurrentTable.Rows.Add(dr);
   }
 
   void grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
       DataTable current = (DataTable)Session["GridData"];
       RadGrid grid = (RadGrid)sender;
       grid.DataSource = current;
 
 
   }
 
   static DataTable GetTable()
   {
       //
       // Here we create a DataTable with a few columns.
       //
       // Create Datatable to store all colums
       DataTable dt = new DataTable();
       DataRow dr = null;
       dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
       dt.Columns.Add(new DataColumn("Size", typeof(string)));
       dt.Columns.Add(new DataColumn("Description", typeof(string)));
       dt.Columns.Add(new DataColumn("Quantity", typeof(string)));
       dt.Columns.Add(new DataColumn("Unit", typeof(string)));
       dt.Columns.Add(new DataColumn("Duration", typeof(string)));
       dt.Columns.Add(new DataColumn("DurationType", typeof(string)));
       dt.Columns.Add(new DataColumn("Amount", typeof(string)));
       dr = dt.NewRow();
       dr["RowNumber"] = 1;
       dr["Size"] = string.Empty;
       dr["Description"] = string.Empty;
       dr["Quantity"] = string.Empty;
       dr["Unit"] = string.Empty;
       dr["Duration"] = string.Empty;
       dr["DurationType"] = string.Empty;
       dr["Amount"] = string.Empty;
       dt.Rows.Add(dr);
 
       dr = dt.NewRow();
       dr["RowNumber"] = 2;
       dr["Size"] = string.Empty;
       dr["Description"] = string.Empty;
       dr["Quantity"] = string.Empty;
       dr["Unit"] = string.Empty;
       dr["Duration"] = string.Empty;
       dr["DurationType"] = string.Empty;
       dr["Amount"] = string.Empty;
       dt.Rows.Add(dr);
 
       dr = dt.NewRow();
       dr["RowNumber"] = 3;
       dr["Size"] = string.Empty;
       dr["Description"] = string.Empty;
       dr["Quantity"] = string.Empty;
       dr["Unit"] = string.Empty;
       dr["Duration"] = string.Empty;
       dr["DurationType"] = string.Empty;
       dr["Amount"] = string.Empty;
       dt.Rows.Add(dr);
 
       dr = dt.NewRow();
       dr["RowNumber"] = 4;
       dr["Size"] = string.Empty;
       dr["Description"] = string.Empty;
       dr["Quantity"] = string.Empty;
       dr["Unit"] = string.Empty;
       dr["Duration"] = string.Empty;
       dr["DurationType"] = string.Empty;
       dr["Amount"] = string.Empty;
       dt.Rows.Add(dr);
 
       dr = dt.NewRow();
       dr["RowNumber"] = 5;
       dr["Size"] = string.Empty;
       dr["Description"] = string.Empty;
       dr["Quantity"] = string.Empty;
       dr["Unit"] = string.Empty;
       dr["Duration"] = string.Empty;
       dr["DurationType"] = string.Empty;
       dr["Amount"] = string.Empty;
       dt.Rows.Add(dr);
       return dt;
   }
 
   static DataTable GetTableForDropDown()
   {
       //
       // Here we create a DataTable with a few columns.
       //
       // Create Datatable to store all colums
       DataTable dt = new DataTable();
       DataRow dr = null;
       dt.Columns.Add(new DataColumn("DurationType", typeof(string)));
 
       dr = dt.NewRow();
       dr["DurationType"] = "Hours";
       dt.Rows.Add(dr);
 
       dr = dt.NewRow();
       dr["DurationType"] = "Days";
       dt.Rows.Add(dr);
 
       dr = dt.NewRow();
       dr["DurationType"] = "Weeks";
       dt.Rows.Add(dr);
 
       dr = dt.NewRow();
       dr["DurationType"] = "Months";
       dt.Rows.Add(dr);
       return dt;
   }
 
   private void ResetRowID(DataTable dt)
   {
       int rowNumber = 1;
 
       if (dt.Rows.Count > 0)
       {
           foreach (DataRow row in dt.Rows)
           {
               row[0] = rowNumber;
               rowNumber++;
           }
       }
   }

Thanks,
Princy
0
Brad
Top achievements
Rank 1
answered on 24 Sep 2013, 12:34 PM
Yes, it worked, thank you very much for your help.

I had GridFormDataItem instead of GridEditableItem, as soon as i switched it, everything started working.
0
Rich
Top achievements
Rank 1
answered on 08 Feb 2019, 02:28 PM

I am trying to implement something similar but the values and the display field are different in my case. 

I have ddl.DataTextField = "DurationType"; -- String value
            ddl.DataValueField = "DurationTypeKey"; -- an int value

 

I want to display the string value in the grid and while editing but also store the key value in the datatable bound to the grid.

0
Eyup
Telerik team
answered on 13 Feb 2019, 06:15 AM
Hello Rich,

You can check the various options to achieve this requirement listed here:
https://www.telerik.com/forums/how-to-have-dropdownlist-and-textbox-inside-a-radgrid#A9aPQyI5vE-ENWi8clmy6Q

If you choose to go with a Template column and your grid is being created programmatically, you can check this section:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/creating-a-radgrid-programmatically#creating-template-columns-programmatically

An important point here is that the entire grid should be created at Page_Init.

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Brad
Top achievements
Rank 1
Answers by
Brad
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Rich
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or