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

Itemtemplate on NOT bound control

2 Answers 65 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
ManniAT
Top achievements
Rank 2
ManniAT asked on 20 Jul 2009, 09:59 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 21 Jul 2009, 07:14 AM
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.
0
ManniAT
Top achievements
Rank 2
answered on 21 Jul 2009, 10:41 AM
Hi Albert,

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

Cheers
Manfred
Tags
ComboBox
Asked by
ManniAT
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
ManniAT
Top achievements
Rank 2
Share this question
or