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

Get Comobbox at code behind in grid

1 Answer 33 Views
ComboBox
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:20 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"
        OnDeleteCommand="gridPostCode_DeleteCommand"
        onitemcommand="gridPostCode_ItemCommand">
        <MasterTableView DataKeyNames="Id" Width="100%" CommandItemDisplay="Top" EditMode="InPlace">
            <Columns>
                <telerik:GridBoundColumn UniqueName="Id" HeaderText="Id" DataField="Id" ReadOnly="true" />
                <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Product Name"
                    SortExpression="Product Name">
                    <ItemTemplate>
                        <%#DataBinder.Eval(Container.DataItem,"ProductId")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox OnItemsRequested="cmbProducts_ItemsRequested" EnableLoadOnDemand="True"
                            ID="cmbProducts" runat="server" Height="140px" Width="150px" >
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>              
                <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" />
                </telerik:GridEditCommandColumn>               
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

-- 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");
        }
    }

Thanks.
Kishor Dalwadi

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 09 Aug 2010, 10:57 AM
Hi Kishor,

Since the ItemCommand is too early for rendering the editform controls, you need to use the code in ItemDataBound event instead.

Code sample:
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");
        // Set the SelectedValue for combo
    }
}


-Shinu.
Tags
ComboBox
Asked by
Kishor Dalwadi
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 1
Share this question
or