Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q2 2011 released 07/12/2011
select

ListBox / Item Templates

  
  • product image Spinning Reel 1 1 bearing
  • product image Spinning Reel 2 1 bearing
  • product image Spinning Reel 3 1 bearing
  • product image Spinning Reel 4 1 bearing
  • product image Spinning Reel 5 1 bearing
  • product image Spinning Reel 6 1 bearing
  • product image Spinning Reel 7 1 bearing
  • product image Spinning Reel 8 1 bearing

  • You can control the way items are rendered by using the ItemTemplate property of RadListBox. Do not forget to call the DataBind method if you are using databinding expressions (<%# %>) in the template

    Example

    ASPX

    <telerik:RadListBox runat="server" ID="RadListBox1">
    	<ItemTemplate>
    		<img src='<%# DataBinder.Eval(Container, "Value") %>' />
    		<%# DataBinder.Eval(Container, "Text") %> -
    		<%# DataBinder.Eval(Container, "Attributes['Price']") %>
    	</ItemTemplate>
    </telerik:RadListBox>
    

    C#

    public void Page_Load(object sender, EventArgs e)
    {
    	if (!Page.IsPostBack)
    	{
    		RadListBox1.DataBind();
    	}
    }
    

    VB.NET

    Public Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    	If Not Page.IsPostBack Then
    		RadListBox1.DataBind()
    	End If
    End Sub
    

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="VB" AutoEventWireup="true" CodeFile="DefaultVB.aspx.vb" Inherits="ListBox_Examples_Functionality_Templates_DefaultVB" %>

    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag runat="server" ID="Headtag1" />
        <link href="styles.css" rel="stylesheet" type="text/css" />
        
        <style type="text/css">
         /* The default display: inline needs to be overrided to resize the container to hold with the content */
         div.RadListBox .rlbTemplate
         {
             display: inline-block;
         }
        </style>
    </head>
    <body class="BODY">
        <form runat="server" id="mainForm" method="post">
        <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
        <qsf:Header runat="server" ID="Header1" NavigationLanguage="VB" />
            <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1">
            <div class="example-panel">
                <div class="order-panel">
                    <label class="product-list">
                        Product list</label>
                    <label class="detail">
                        Detail View &amp; Purchase</label>
                    <telerik:RadListBox ID="RadListBox1" runat="server" AllowTransfer="true" AutoPostBackOnTransfer="true"
                        Height="200px" OnTransferred="RadListBox1_Transferred" SelectionMode="Multiple"
                        TransferToID="RadListBox2" Width="215px">
                        <ButtonSettings ShowTransferAll="false" VerticalAlign="Middle" />
                        <ItemTemplate>
                            <img class="product-image" src='Images/<%# DataBinder.Eval(Container, "Value")%>' alt="product image"/>
                            <span class="product-title">
                                <%# DataBinder.Eval(Container, "Text")%></span> <span class="bearing">1 bearing</span>
                        </ItemTemplate>
                        <Items>
                            <telerik:RadListBoxItem Text="Spinning Reel 1" Value="reel1_thumb.png" Price="99" Selected="true" />
                            <telerik:RadListBoxItem Text="Spinning Reel 2" Value="reel2_thumb.png" Price="199" />
                            <telerik:RadListBoxItem Text="Spinning Reel 3" Value="reel3_thumb.png" Price="99" />
                            <telerik:RadListBoxItem Text="Spinning Reel 4" Value="reel4_thumb.png" Price="299" />
                            <telerik:RadListBoxItem Text="Spinning Reel 5" Value="reel5_thumb.png" Price="199" />
                            <telerik:RadListBoxItem Text="Spinning Reel 6" Value="reel6_thumb.png" Price="99" />
                            <telerik:RadListBoxItem Text="Spinning Reel 7" Value="reel7_thumb.png" Price="299" />
                            <telerik:RadListBoxItem Text="Spinning Reel 8" Value="reel8_thumb.png" Price="199" />
                        </Items>
                    </telerik:RadListBox>
                    <telerik:RadListBox runat="server" ID="RadListBox2" Height="200px" Width="270px"
                        SelectionMode="Multiple">
                        <ItemTemplate>
                            <img class="product-image" src='Images/<%# DataBinder.Eval(Container, "Value")%>' alt="product image"/>
                            <span class="detail-title">
                                <%# DataBinder.Eval(Container, "Text")%></span> <span class="bearing">1 bearing</span>
                            <ul class="details">
                                <li>
                                    <label>
                                        Price:</label>
                                    <span>
                                        <%# Convert.ToInt32(DataBinder.Eval(Container, "Attributes['Price']")).ToString("C0") %></span>
                                </li>
                                <li>
                                    <label>
                                        Quantity:</label>
                                    <telerik:RadNumericTextBox runat="server" ID="QuantityTextBox" Width="40px" MinValue="1"
                                        MaxValue="10" ShowSpinButtons="true" Value="1" NumberFormat-DecimalDigits="0" />
                                </li>
                            </ul>
                        </ItemTemplate>
                        <Items>
                            <telerik:RadListBoxItem Text="Spinning Reel 9" Value="reel9.png" Price="99" />                    
                        </Items>
                    </telerik:RadListBox>
                </div>
            </div>
        </telerik:RadAjaxPanel>
        <qsf:Footer runat="server" ID="Footer1" />
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451