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

Use change generated columns edit type

4 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
chris lively
Top achievements
Rank 1
chris lively asked on 24 Sep 2010, 03:45 PM
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?

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Sep 2010, 01:39 PM
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.
0
chris lively
Top achievements
Rank 1
answered on 28 Sep 2010, 06:45 AM
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.
0
Accepted
Mira
Telerik team
answered on 29 Sep 2010, 02:49 PM
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
0
TheLostLeaf
Top achievements
Rank 2
answered on 07 Oct 2010, 06:53 PM
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
Tags
Grid
Asked by
chris lively
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
chris lively
Top achievements
Rank 1
Mira
Telerik team
TheLostLeaf
Top achievements
Rank 2
Share this question
or