New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Templates Overview
Templates allow you to embed any context inside a RadDropDownListItem. For example:
-
HTML markup
-
ASP.NET server controls
-
other third-party controls (other Telerik RadControls for ASP.NET Ajax for example)
Example
Shows how to use templates to create the following RadDropDownList:
An
C#
<telerik:RadDropDownList RenderMode="Lightweight" ID="RadDropDownList1"
runat="server">
<ItemTemplate>
<table >
<tr>
<td>
<img src='Images/<%# DataBinder.Eval(Container, "Attributes['ImagePath']") %>' alt="" />
</td>
<td>
<%# DataBinder.Eval(Container, "Text") %>
</td>
</tr>
</table>
</ItemTemplate>
<Items>
<telerik:DropDownListItem ImagePath="additionOperation.png" Text="Sign for Adding" />
<telerik:DropDownListItem ImagePath="substractOperation.png" Text="Sign for Substracting" />
<telerik:DropDownListItem ImagePath="multiplyOperation.png" Text="Sign for Multiplying" />
<telerik:DropDownListItem ImagePath="divideOperation.png" Text="Sign for Dividing" />
</Items>
</telerik:RadDropDownList>
Before the template can use the RadDropDownList item's properties to bind the elements in the template, the application needs to explicitly bind the items by calling DataBind method of RadDropDownListItem objects.
C#
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < RadDropDownList1.Items.Count; i++)
{
RadDropDownList1.Items[i].DataBind();
}
}