Why are template items inaccessible?

5 posts, 1 answers
  1. Steven
    Steven avatar
    84 posts
    Member since:
    Oct 2010

    Posted 15 Aug 2011 Link to this post

    I am trying to populate a rad combo box via a object data source, but I cannot seem to access it when I put it into a RadRibbonBar.

    Am I missing something?   Here is what I have:

    <telerik:RadRibbonBar runat="server">
        <telerik:RibbonBarTab Text="Home">
            <telerik:RibbonBarGroup Text="Selections" >
                <Items>
                    <telerik:RibbonBarTemplateItem>
                        <telerik:RadComboBox ID="versionList" Label="Version" runat="server" 
                            DataTextField="Version.Name" DataValueField="Version.ID" >
                        </telerik:RadComboBox>
                    </telerik:RibbonBarTemplateItem>
                </Items>
            </telerik:RibbonBarGroup>
        </telerik:RibbonBarTab>
    </telerik:RadRibbonBar>

    In my code, versionList is not recognized as an object and I cannot bind to it.   As shown below.   "versionList" is not defined.

    versionList.DataSource = version.Items;

    What am I doing wrong?


  2. Answer
    Kate
    Admin
    Kate avatar
    1898 posts

    Posted 16 Aug 2011 Link to this post

    Hi Steven,

    Here is how you can access a RadComboBox control when it is inside a RadRibbonBarTemplate:

    markup:
    <telerik:RadRibbonBar ID="RadRibbonBar1" runat="server" SelectedTabIndex="0">
                <telerik:RibbonBarTab Text="tab1">
                    <telerik:RibbonBarGroup Text="Group1" EnableLauncher="false" Value="1">
                        <Items>
                        <telerik:RibbonBarButton Size="Medium" Text="New" />
                        <telerik:RibbonBarButton Size="Medium" Text="Edit"  />
                        </Items>
                    </telerik:RibbonBarGroup>
                </telerik:RibbonBarTab>
                <telerik:RibbonBarTab Text="tab2" Value="tab2">
                    <telerik:RibbonBarGroup Text="Font">
                        <Items>
                            <telerik:RibbonBarTemplateItem>
                                <Template>
                                    <telerik:RadComboBox ID="RadComboBox1" runat="server" Width="90px">
                                        <Items>
                                            <telerik:RadComboBoxItem Text="Cambria" />
                                            <telerik:RadComboBoxItem Text="Calibri" Selected="true" />
                                            <telerik:RadComboBoxItem Text="Arial" />
                                            <telerik:RadComboBoxItem Text="Book Antiqua" />
                                        </Items>
                                    </telerik:RadComboBox>
                                </Template>
                            </telerik:RibbonBarTemplateItem>
                        </Items>
                    </telerik:RibbonBarGroup>
                </telerik:RibbonBarTab>
            </telerik:RadRibbonBar>

    code behind:
    protected void Page_Load(object sender, EventArgs e)
        {                      
            RibbonBarTab tab2 = RadRibbonBar1.FindTabByValue("tab2");
            RadComboBox combo1 = (RadComboBox)tab2.Groups[0].Items[0].FindControl("RadComboBox1");
        }

    Regards,
    Kate
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Steven
    Steven avatar
    84 posts
    Member since:
    Oct 2010

    Posted 16 Aug 2011 Link to this post

    Is this documented somewhere that I can read more about this?
  5. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 17 Aug 2011 Link to this post

    Hi Steven,

    Since the RadRibbonBar is a new control, its documentation is still not very rich in terms of different scenarios. Therefore this is still not documented. However, I will make sure to include it as a new help article. Meanwhile here is some more explanation on the code above.

    In order to find the control that is located in a Template of a RadRibbonBar, first you need to find the tab that it is located in. This is done by using the FindTabByValue property (note that to make this work, the tab needs to have a previously assigned value, ex:  <telerik:RibbonBarTab Text="tab2" Value="tab2"> )
    Then you will need to find the Group by its index (this is zero in the particular case - Groups[0]) that is placed in the tab with Value="tab2" and get the Group's first item (again this is done by index - Items[0]). Further, by using the FindControl property you can access the RadComboBox control.  

    I hope this is more clear. 

    Best wishes,
    Kate
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  6. Steven
    Steven avatar
    84 posts
    Member since:
    Oct 2010

    Posted 17 Aug 2011 Link to this post

    Thank you for the information.  

    I understand this is a new control, especially when dealing with the template items, which is part of the newest release, and with that the documentation tends to lag a little.  

    What I was surprised about though, was that the object was not directly accessible, but that you had to go through a find function, especially when dealing with template items.

    I hope that is something that will change in the future.

    Thanks again for all your help.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017