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

Get Comobbox at code behind in grid

1 Answer 60 Views
This is a migrated thread and some comments may be shown as answers.
Kishor Dalwadi
Top achievements
Rank 2
Kishor Dalwadi asked on 09 Aug 2010, 08:33 AM
Hello Sir, I am Using Combobox in RadGrid Edit Tempate.

Code is Given Below.

I want combobox for insert and set value from codebehind.

And SelecetedValue is not woking in edittemplate.

Please Give me proper solution.

---- ASPX Code ---
<telerik:RadGrid ID="gridPostCode" runat="server" Width="96%" GridLines="None" AutoGenerateColumns="False"
        PageSize="10" AllowSorting="True" AllowPaging="True" OnUpdateCommand="gridPostCode_UpdateCommand"
        OnNeedDataSource="gridPostCode_NeedDataSource" ShowStatusBar="true" OnInsertCommand="gridPostCode_InsertCommand"
        <MasterTableView DataKeyNames="Id" Width="100%" CommandItemDisplay="Top" EditMode="InPlace">
                <telerik:GridBoundColumn UniqueName="Id" HeaderText="Id" DataField="Id" ReadOnly="true" />
                <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Product Name"
                    SortExpression="Product Name">
                        <telerik:RadComboBox OnItemsRequested="cmbProducts_ItemsRequested" EnableLoadOnDemand="True"
                            ID="cmbProducts" runat="server" Height="140px" Width="150px" >
                <telerik:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="~/Images/edit-icon.png"
                    UpdateImageUrl="~/Images/edit-icon.png" UniqueName="EditCommandColumn" HeaderText="Modify"
                    HeaderStyle-HorizontalAlign="Center" CancelImageUrl="~/Images/delete-icon.png">
                    <ItemStyle Width="50px" HorizontalAlign="Center" />

-- CS Code--
 protected void gridPostCode_ItemCommand(object source, GridCommandEventArgs e)
        if (e.CommandName == "Edit")
            GridEditableItem item = e.Item as GridEditableItem;
            RadComboBox ddl = (RadComboBox)item.FindControl("cmbProducts");

Kishor Dalwadi

1 Answer, 1 is accepted

Sort by
Top achievements
Rank 2
answered on 09 Aug 2010, 10:55 AM
Hello Kishor Dalwadi,

The ItemCommand is too early to render the editform controls. So you can try the code in ItemDataBound event instead.

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        GridEditableItem editItem = (GridEditableItem)e.Item;
        RadComboBox combo = (RadComboBox)editItem.FindControl("cmbProducts");
        // combo.Enabled = false; // Set the SelectedValue here

Asked by
Kishor Dalwadi
Top achievements
Rank 2
Answers by
Top achievements
Rank 2
Share this question