Radcombobox

6 posts, 0 answers
  1. Vitaly
    Vitaly  avatar
    76 posts
    Member since:
    Aug 2011

    Posted 07 Nov 2013 Link to this post

    Good morning,
    is this possible to have radcombobox inside the other radcombobox.
    If yes,could you please sent an example.

    Thanks.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Nov 2013 Link to this post

    Hi Vitaly,

    Please have a look into the code snippet to show a RadComboBox inside another RadComboBox.

    ASPX:
    <telerik:RadComboBox ID="RadComboBoxMain" runat="server" Height="100px" Width="200px">
        <Items>
            <telerik:RadComboBoxItem Text="ITEM 1" Value="SELECT ITEM"></telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem Text="ITEM 2" Value="SELECT ITEM"></telerik:RadComboBoxItem>
        </Items>
        <ItemTemplate>
            <telerik:RadComboBox Style="z-index: 7000;" ID="RadComboBoxInner" runat="server">
                <Items>
                    <telerik:RadComboBoxItem runat="server" Text="ITEM1" Value="SELECT ITEM"></telerik:RadComboBoxItem>
                    <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem2" Value="RadComboBoxItem2" />
                </Items>
            </telerik:RadComboBox>
        </ItemTemplate>
    </telerik:RadComboBox>

    Hope this will helps you.
    Thanks,
    Princy.
  3. Vitaly
    Vitaly  avatar
    76 posts
    Member since:
    Aug 2011

    Posted 08 Nov 2013 Link to this post

    Thanks for your quick respond.I should tell you in  more details what I need:

    I need main RadCombobox with 3 items:
    item 1:Text="TR"
    item 2:Text="Processed"
    item 3:Text="All"

    And I need inner RadCombobox which will only come from first item in main RadCombobox:
    Text="Approved"
    Text="Entered"
    Text="Trans"

    In main RadCombobox item2 and item3 stays alone.

    Thanks so much for your help.

  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 11 Nov 2013 Link to this post

    Hi Vitaly,

    I guess you want to show the inner RadComboBox for only the First Item of the Main RadComboBox. Please have a look into the sample code I tried.

    ASPX:
    <telerik:RadComboBox ID="RadComboBoxMain" runat="server" Height="100px" Width="200px"
        OnSelectedIndexChanged="RadComboBoxMain_SelectedIndexChanged" AutoPostBack="true">
        <Items>
            <telerik:RadComboBoxItem Text="TR"></telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem Text="Processed" Selected='true'></telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem Text="All" />
        </Items>
    </telerik:RadComboBox>

    C#:
    protected void RadComboBoxMain_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
    {
        if (e.Text == "TR")
        {
            RadComboBox inner = new RadComboBox();
            inner.ID = "innercombo";
            RadComboBoxItem item1 = new RadComboBoxItem();
            item1.Text = "Approved";
            RadComboBoxItem item2 = new RadComboBoxItem();
            item2.Text = "Entered";
            RadComboBoxItem item3 = new RadComboBoxItem();
            item3.Text = "Trans";
            item3.Selected = true;
            inner.Items.Add(item1);
            inner.Items.Add(item2);
            inner.Items.Add(item3);
            inner.Style.Add("z-index", "7000");
            RadComboBoxMain.Items[0].Controls.Add(inner); 
        }
    }

    Thanks,
    Princy.
  5. Vitaly
    Vitaly  avatar
    76 posts
    Member since:
    Aug 2011

    Posted 12 Nov 2013 Link to this post

    Thanks again for your respond.
    It is working but I do have question.
    If I choose from inner combobox "Approved" how can I grab this value or text into C# programmatically?

    Thanks for your help.
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 13 Nov 2013 Link to this post

    Hi Vitaly,

    You can try the following C# code.

    C#:
    RadComboBox combo1 = (RadComboBox)RadComboBoxMain.Items[0].FindControl("innercombo");
    string text = combo1.SelectedItem.Text;

    Since controls added from code behind are lost on postback you can add the inner combobox in the Page_Load() as follows.

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (RadComboBoxMain.SelectedItem.Text == "TR")
        {
            RadComboBox inner = new RadComboBox();
            inner.ID = "innercombo";
            RadComboBoxItem item1 = new RadComboBoxItem();
            item1.Text = "Approved";
            RadComboBoxItem item2 = new RadComboBoxItem();
            item2.Text = "Entered";
            RadComboBoxItem item3 = new RadComboBoxItem();
            item3.Text = "Trans";
            item3.Selected = true;
            inner.Items.Add(item1);
            inner.Items.Add(item2);
            inner.Items.Add(item3);
            inner.Style.Add("z-index", "7000");
            RadComboBoxMain.Items[0].Controls.Add(inner);
        }
    }

    Thanks,
    Princy.
Back to Top