Use change generated columns edit type

5 posts, 1 answers
  1. chris lively
    chris lively avatar
    11 posts
    Member since:
    Sep 2009

    Posted 24 Sep 2010 Link to this post

    I have the following grid definition:

    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="true" AllowMultiRowEdit="true" 
    GridLines="None" Skin="Web20" 
    <MasterTableView EditMode="InPlace" TableLayout="Fixed">

    Instead of the default textbox, I want the generated columns to be a drop down list.  All of the selections are the same.  I have to do this at runtime as I don't know how many rows or columns I have until then.

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 Sep 2010 Link to this post

    Hello Chris,

    I hope hiding the default textbox control in editmode and adding the new dropdownlist control will help you to achieve the requirement.

    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource3" AutoGenerateColumns="true"
        AllowMultiRowEdit="true" GridLines="None" Skin="Web20"
        <MasterTableView EditMode="InPlace" TableLayout="Fixed">

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
           if (e.Item is GridEditableItem && e.Item.IsInEditMode)
               GridEditableItem editItem = (GridEditableItem)e.Item;
               int i = 0;
               foreach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
                   string uniqueName = RadGrid1.MasterTableView.AutoGeneratedColumns[i].UniqueName;// get the ColumnUniqueName of Autogenerated column
                   // creating DropDownList
                   DropDownList list = new DropDownList();
                   list.DataSourceID = "SqlDataSource3"; // set your DataSource
                   list.DataTextField = uniqueName;
                   list.DataValueField = uniqueName;
                   // hide default TextBox
                   TextBox txtid = (TextBox)editItem[uniqueName].Controls[0];
                   txtid.Visible = false;
                   // find Table cell and add DropDownList to that Table cell
                   TableCell cell1 = (TableCell)editItem[uniqueName];

    Also another approach is creating the columns dynamically which includes RadComboBox inside EditItemTemplate. Go through the following link to know more on creating the columns programmatically.
    Programmatic creation

  3. chris lively
    chris lively avatar
    11 posts
    Member since:
    Sep 2009

    Posted 28 Sep 2010 Link to this post

    That didn't work at all.

    I came close with this answer:

    However, the problem with that one is that it doesn't work when AllowMultiRowEdit is true.  It will only show the last line of controls.
  4. Answer
    Mira avatar
    1124 posts

    Posted 29 Sep 2010 Link to this post

    Hello Chris,

    I have followed your scenario and prepared a sample project for you demonstrating how the desired functionality can be implemented. You can find it attached to this message.

    I hope it helps.

    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. TheLostLeaf
    TheLostLeaf avatar
    34 posts
    Member since:
    Feb 2007

    Posted 07 Oct 2010 Link to this post

    Thanks ! This is exactly what I needed. It's nice to use the automated forms for ease and just override a few items for customizations.

    Works great.

Back to Top