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

How to use RadCombox as InPlace editor

2 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Al
Top achievements
Rank 1
Iron
Iron
Iron
Al asked on 15 Jan 2015, 09:17 AM
Hi,
I have my grid setup like this:               

<Columns>
                <telerik:GridBoundColumn DataField="col1" HeaderText="Col 1" UniqueName="mytxt" />
                <telerik:GridDropDownColumn DataField="col2" UniqueName="mydd" DropDownControlType="RadComboBox"  HeaderText="Col 2" />                                     
</Columns>


Now I have some questions relating to this:

1. Do I need to manually handle the populating of the field for 'view' mode? Unless I use the code below in ItemDataBound then in view mode the dropdown column is empty.           

if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                DataRowView row = (DataRowView)e.Item.DataItem;
                item["mydd"].Text = row["col2"].ToString();
            }


2. Why does the drop down column have no controls, in ItemDataBound:           

if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
            GridEditableItem item = (GridEditableItem)e.Item; 
             
            //Controls has one control:
            //RadTextBox = (RadTextBox)item["mytxt"].Controls[0]; 
             
            //Controls is empty:
            //RadComboBox com = (RadComboBox)item["mydd"].Controls[0];
 }


3. Is it possible to use a non-datasource-bound combo? so in ItemDataBound I would do something like this:  
         
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
            GridEditableItem item = (GridEditableItem)e.Item;
 
            RadComboBox com = (RadComboBox)item["mydd"].Controls[0];
            com.Items.Add(new RadComboxItem("a", "a"));
            com.Items.Add(new RadComboxItem("b", "b"));
 }

2 Answers, 1 is accepted

Sort by
0
Al
Top achievements
Rank 1
Iron
Iron
Iron
answered on 15 Jan 2015, 02:01 PM
I can't explain the behaviour above, but I have since read that the RadComboBox is intended to be used only with datasources & I suspect that has something to do with matters.Anyway, I have pieced together this code that seems to work - Using a Radcombox as an edit item (which is populated is code):

<telerik:GridTemplateColumn UniqueName="mytmpl">
    <ItemTemplate>
        <asp:Label ID="Label1" runat="server" Text='<%# Eval("col2") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadComboBox runat="server" ID="COMBO"></telerik:RadComboBox>
    </EditItemTemplate>
</telerik:GridTemplateColumn>

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem item = (GridEditableItem)e.Item;
 
        RadComboBox combo = (RadComboBox)item.FindControl("COMBO");
        combo.Items.Add(new RadComboBoxItem("person", "person"));
        combo.Items.Add(new RadComboBoxItem("computer", "computer"));
 
        combo.SelectedValue = ((DataRowView)e.Item.DataItem)["col2"].ToString();
    }           
     
}

0
Eyup
Telerik team
answered on 20 Jan 2015, 09:08 AM
Hi Al,

When using GridDropDownColumn you will need also to define data, text and value field properties:
http://www.telerik.com/help/aspnet-ajax/grid-column-types.html#dropdown

Here you can find a live sample:
http://demos.telerik.com/aspnet-ajax/grid/examples/columns-rows/columns/column-types/defaultcs.aspx

If you decide to create the combo manually using a template, you can check the various binding options provided by RadComboBox:
http://www.telerik.com/help/aspnet-ajax/combobox-server-side-itemsrequested.html

Hope this helps.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Al
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Al
Top achievements
Rank 1
Iron
Iron
Iron
Eyup
Telerik team
Share this question
or