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

Adding RadCombobox in RadGrid

3 Answers 199 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pradeep
Top achievements
Rank 1
Pradeep asked on 15 Oct 2013, 12:05 PM
How to add radcombobox with items inside radgrid..?

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 15 Oct 2013, 12:21 PM
Hi Pradeep,

I'm not sure about your requirement.Please try the below code snippet.If this doesn't help,Please elaborate on your requirements.

ASPX:
<telerik:GridTemplateColumn>
    <ItemTemplate>
        <telerik:RadComboBox ID="RadComboBox1" runat="server">
            <Items>
                <telerik:RadComboBoxItem Value="1" Text="1" />
                <telerik:RadComboBoxItem Value="2" Text="2" />
            </Items>
        </telerik:RadComboBox>
    </ItemTemplate>
</telerik:GridTemplateColumn>

Thanks,
Princy
0
Pradeep
Top achievements
Rank 1
answered on 15 Oct 2013, 12:36 PM
I want to add one gridbound column and radcombobox inside radgrid but after adding and building it shows radcombobox doesn't exist in the current context..
0
Princy
Top achievements
Rank 1
answered on 16 Oct 2013, 04:13 AM
Hi Pradeep,

Please try the following code snippet,it shows how to access the RadComboBox and BoundColumn from code behind.If this doesn't help,please provide your code.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateEditColumn="true" OnItemDataBound="RadGrid1_ItemDataBound">
    <MasterTableView DataKeyNames="OrderID">
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" />       
            <telerik:GridTemplateColumn>
                <ItemTemplate>
                    <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
                        <Items>
                            <telerik:RadComboBoxItem Value="1" Text="1" />
                            <telerik:RadComboBoxItem Value="2" Text="2" />
                        </Items>
                    </telerik:RadComboBox>
                </ItemTemplate>
                <EditItemTemplate>               
                    <telerik:RadComboBox ID="RadComboBox1" runat="server">
                        <Items>
                            <telerik:RadComboBoxItem Value="1" Text="1" />
                            <telerik:RadComboBoxItem Value="2" Text="2" />
                        </Items>
                    </telerik:RadComboBox>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item=(GridDataItem)e.Item;
        string datakeyval = item.GetDataKeyValue("OrderID").ToString(); //Access datakeyvalue in view mode
        string boundcolval = item["UniqueName"].Text; //Access BoundColumn in view mode
        RadComboBox combo = (RadComboBox)item.FindControl("RadComboBox1");//Access the template column value in view mode
        string comboval = combo.SelectedValue;
            
    }
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem data = (GridEditableItem)e.Item;
        TextBox txt = (TextBox)data["OrderID"].Controls[0];//Access Bound column in edit mode
        RadComboBox combo = (RadComboBox)data.FindControl("RadComboBox1");//Access Template column in edit mode          
    }
}
protected void RadComboBox1_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
    //Accessing the value on the SelectedIndexChange event
    string val=e.Text;
}

Thanks,
Princy
Tags
Grid
Asked by
Pradeep
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Pradeep
Top achievements
Rank 1
Share this question
or