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" 
    OnPreRender="RadGrid1_PreRender" 
    >
    <MasterTableView EditMode="InPlace" TableLayout="Fixed">
    <Columns>
    </Columns>
    </MasterTableView>
    </telerik:RadGrid>

    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.

    Ideas?
  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.

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

    C#:
    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];
                   cell1.Controls.Add(list);
                   i++;
               }
            }
       }

    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


    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. 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: http://www.telerik.com/community/forums/aspnet-ajax/grid/createcolumneditor-event-to-change-editor-control-type.aspx#1360068

    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.
  5. Answer
    Mira
    Admin
    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.

    Regards,
    Mira
    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
  6. 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.

    -Eric
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017