New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Binding Templates

Often, when you use tab templates, you want the controls in the template to display information associated with the tab properties. For example, consider a simple tab strip with a check box in the item template:

<telerik:RadTabStrip RenderMode="Lightweight" ID="RadTabStrip1" runat="server" SelectedIndex="0">  
        <telerik:RadTab runat="server" Text="Products" Selected="True" SelectedIndex="0">      
        <telerik:RadTab runat="server" Text="Food" Selected="True" />        
        <telerik:RadTab runat="server" Text="Electronics" />      
        <telerik:RadTab runat="server" Text="Tours">      
        <telerik:RadTab runat="server" Text="Europe" />        
        <telerik:RadTab runat="server" Text="South Pacific" />      
        <asp:CheckBox ID="CheckBox1" runat="server" />  

When you run the application, the tabs all show check boxes with no labels: template no binding

This is hardly useful! To override the properties of the check box in the template, use a DataBinder.Eval statement:

<pre xmlns="">
    <asp:CheckBox ID="CheckBox1" Text='<%# DataBinder.Eval(Container, "Text") %>'    
    Checked='<%# DataBinder.Eval(Container, "Selected") %>'    
    runat="server" />

In the DataBinder.Eval statement, Container is the RadTab and "Text" or "Selected" identifies the Text or Selected property of that item.

In this example, the first parameter to the DataBinder.Eval statement is Container , because the tabs are statically bound. If the tab strip was bound to a data source, then you must use Container.DataItem instead. e.g.<%#DataBinder.Eval(Container.DataItem, "TextField") %>

In addition to adding a DataBinder.Eval statement, you must also explicitly call the DataBind method for the tabs so that the template has access to the properties of the tab:

protected void Page_Load(object sender, EventArgs e) 
    for (int i = 0; i < RadTabStrip1.Tabs.Count; i++) 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Dim i As Integer = 0
    While i < RadTabStrip1.Tabs.Count
        System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
    End While
End Sub 

Now the check boxes reflect the properties of the tabs:

Templates Bound

In this article