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

ComboBox / Custom Attributes

select
Update
BorBou Ken Edwards (23 y)

  • RadComboBox provides support for custom attributes. You can specify custom attributes declaratively in the RadComboBoxItem tag or programmatically using the Attributes collection of the RadComboBoxItem. You can also access custom attributes client-side, using the get_attributes collection of the RadComboBoxItem client-side instance.

    You can use databinding expressions in the ItemTemplate template of the combobox. Data-binding expressions have the typical ASP.NET format and syntax, i.e.

    Example: <%# DataBinder.Eval(Container, "Attributes['ImagePath']") %>

    Please note the following:

    If you need to use templates and access custom attributes of the items in the templates you should explicitely bind (call the DataBind() method) these items. The RadComboBoxItem class now exposes the DataBind() method. You should call this method for the items, to which you are going to apply templates. Once the item is bound you can access its Attributes. You can also call the DataBind method of the parent combobox object. This will automatically bind all the items.

    In RadComboBox, the Container object contains two data objects: - DataItem - the current row of the respective datasource. You can access the column needed using the column name as a second argument. Example:
    <%# DataBinder.Eval(Container.DataItem, "Author") %>

    - Item - the current item (ComboBoxItem). You can access all properties and custom attributes of the current combobox item.
    Example: <%# DataBinder.Eval(Container, "Text") %>

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page AutoEventWireup="true" CodeFile="DefaultVB.aspx.vb" Inherits="Telerik.ComboboxExamplesVB.CustomAttributes.DefaultVB" Language="vb" %>
    <%@ 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"></qsf:headtag>
        
            <link rel="stylesheet" type="text/css" href="styles.css" />
        </head>
        <body class="BODY">
         <form runat="server" id="mainForm" method="post">
             <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
             </telerik:RadScriptManager>
            <qsf:header runat="server" ID="Header1" NavigationLanguage="VB" ShowSkinChooser="false"></qsf:header>

            <div id="qsfexWrapper">
                <fieldset>
                    <asp:Label ID="Label1" runat="server" AssociatedControlID="RadTextBox_ScreenName">Screen Name:</asp:Label>
                    <telerik:RadTextBox runat="server" ID="RadTextBox_ScreenName" Text="BorBou" Skin="Black" Width="120px" height="18px"></telerik:RadTextBox>
                    
                    <asp:Label ID="Label2" runat="server" AssociatedControlID="RadTextBox_Name">Name:</asp:Label>
                    <telerik:RadTextBox runat="server" ID="RadTextBox_Name" Text="Ken Edwards" Skin="Black" Width="210px" height="18px"></telerik:RadTextBox>
                    
                    <asp:Label ID="Label3" runat="server" AssociatedControlID="RadTextBox_Age">Age:</asp:Label>
                    <telerik:RadTextBox runat="server" ID="RadTextBox_Age" Text="23" Skin="Black" Width="30px" height="18px"></telerik:RadTextBox>
                
                    <asp:Label ID="Label4" runat="server" AssociatedControlID="RadComboBox_AvatarSelection">Avatar:</asp:Label>
                    <telerik:RadComboBox ID="RadComboBox_AvatarSelection"
                     runat="server"
                        Width="220px"
                        HighlightTemplatedItems="True"
                        Skin="Black"
                        CssClass="qsfexAlignedInput">
                        <ItemTemplate>
                         <!-- ImageClassName, Popularity and Artist are custom attributues of the items.
                         You can add as many as you wish. -->
                            <div class="<%# DataBinder.Eval(Container, "Attributes['ImageClassName']") %>">
                                <span class="qsfexAvatarContainer"></span>
                                <span class="qsfexField">Popularity: <%# DataBinder.Eval(Container, "Attributes['Popularity']")%></span>
                                <span class="qsfexField">Artist: <%# DataBinder.Eval(Container, "Attributes['Artist']")%></span>
                            </div>
                        </ItemTemplate>                    
                        <Items>                    
                            <telerik:RadComboBoxItem
                                ImageClassName="qsfexGeeky"
                                Popularity="358"
                                Artist="Jone Larragne"
                                Text="Geeky">
                            </telerik:RadComboBoxItem>
                            
                            <telerik:RadComboBoxItem
                                ImageClassName="qsfexGirly"
                                Popularity="1,005"
                                Artist="Jone Larragne"
                                Text="Girly">
                            </telerik:RadComboBoxItem>
                            
                            <telerik:RadComboBoxItem
                                ImageClassName="qsfexGrumpy"
                                Popularity="1,345"
                                Artist="Jone Larragne"
                                Text="Grumpy">
                            </telerik:RadComboBoxItem>
                            
                            <telerik:RadComboBoxItem
                                ImageClassName="qsfexGroovie"
                                Popularity="2,043"
                                Artist="Jone Larragne"
                                Text="Groovie">
                            </telerik:RadComboBoxItem>
                        </Items>
                    </telerik:RadComboBox>
        
                    <asp:LinkButton ID="UpdateButton" runat="server" Text="Update" CssClass="qsfexSubmitButton" OnClick="UpdateButton_Click"></asp:LinkButton>
                </fieldset>
                
                <div id="qsfexLogo"></div>
                
                            <div id="qsfexPreview" class="qsfexPreviewPane" runat="server">
                    <span class="qsfexAvatarContainer"></span>
                    <span class="qsfexDisplayName">BorBou</span>
                    <span class="qsfexRealName">Ken Edwards (23 y)</span>
                </div>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="UpdateButton">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="qsfexPreview" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
                <div id="qsfexDecoration1"></div>
                <div id="qsfexDecoration2"></div>
            </div>

            <qsf:footer runat="server" ID="Footer1"></qsf:footer>
        </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