Itemtemplate on NOT bound control

3 posts, 1 answers
  1. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 20 Jul 2009 Link to this post

    Hi,

    I'm a bit confused about the "ItemTemplate" thing.
    From my point of view a template is some thing which tells how to display something.
    So in the case of a Dropdown I have 2 Things - a value and a Text.

    How do I "bind" (or assign) those values to my template?
    Assume a dropdown with items where the value is an address (URL or such a thing) and the text is some kind of "what to show".
    My template should now display a hyperling - with "Text" as display and "Value" as href.

    How to write such a template - if the combobox is NOT databound which means that I can'r retrieve the values from the bound data.
    Instead I want to "extract" them from the item list.

    Regards

    Manfred
  2. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 21 Jul 2009 Link to this post

    Hi ManniAT,

    Here is a codesnippet which should get you started:
    <telerik:RadComboBox runat="server"
        <ItemTemplate> 
            <href='<%# DataBinder.Eval(Container, "Value")%>'><%# DataBinder.Eval(Container, "Text")%></a
        </ItemTemplate> 
        <Items> 
            <telerik:RadComboBoxItem Text="Example" Value="http://www.example.com" /> 
        </Items> 
    </telerik:RadComboBox> 


    In codebehind you need to call the DataBind method of the combobox so the databinding expressions in the template are evaluated.

    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 21 Jul 2009 Link to this post

    Hi Albert,

    thank you for this.
    I guess these lines of code should find their place in the ComboBox/ItemTemplate documentation!

    Cheers
    Manfred
Back to Top