RadComboBox for ASP.NET

Overview Send comments on this topic.
See Also
Custom Attributes > Overview

Glossary Item Box

It is not always possible to provide all properties that might be needed for certain type of scenarios. That is why combobox items (RadComboBoxItem) provide a special collection called Attributes. You can store any number of attributes in the collection as name/value pair.

Using attributes declaratively (ASPX/ASCX file)

In this example, all combobox items have been using the Visual Studio .NET design time support. ImagePath and DisplayName are not properties of RadComboBoxItem, but they are automatically added to the Attributes collection and can be used in Data Binding expressions in ItemTemplate as shown:

ASPX Copy Code
<radcb:RadComboBox
           
id="RadComboBox1"
           
Runat="server"
           
Height="90px"
           
Width="150px"
           
Skin="WindowsOlive"
           
ShowToggleImage="True">
           
<ItemTemplate>
              
<img src='Img/TelerikProducts/<%# DataBinder.Eval(Container, "Attributes['ImagePath']") %>.gif'> <%# DataBinder.Eval(Container, "Attributes['DisplayName']") %>
           
</ItemTemplate>
           
<Items>
              
<radcb:RadComboBoxItem ImagePath="e" DisplayName="RadEditor" Text="RadEditor"></radcb:RadComboBoxItem>
              
<radcb:RadComboBoxItem ImagePath="t" DisplayName="RadTreeView" Text="RadTreeView"></radcb:RadComboBoxItem>
              
<radcb:RadComboBoxItem ImagePath="s" DisplayName="RadSpell" Text="RadSpell"></radcb:RadComboBoxItem>
              
<radcb:RadComboBoxItem ImagePath="m" DisplayName="RadMenu" Text="RadMenu"></radcb:RadComboBoxItem>
              
<radcb:RadComboBoxItem ImagePath="tab" DisplayName="RadTabstrip" Text="RadTabstrip"></radcb:RadComboBoxItem>
           
</Items>
</
radcb:RadComboBox>

Using custom attributes programmatically

You can add any name / value pair (value must be string) in the Attributes collection of each RadComboBoxItem and retrieve it back later.

Example:

C# Copy Code
...
RadComboBoxItem item = new RadComboBoxItem("Some Item");
item.Attributes
["ImagePath"] = "Some Custom Value";
item.Attributes
["DisplayName"] = "Some Custom Value";
...
        
VB.NET Copy Code
...
Dim item As New RadComboBoxItem("Some Item")
item.Attributes("ImagePath") = "Some Custom Value"
item.Attributes("DisplayName") = "Some Custom Value"
...

Using custom attributes client-side

Custom attributes are sent to the client-side API as well. Each client-side instance of RadComboBoxItem has a collection named Attributes that contains all custom attributes for the respective item. Here is an example that demonstrates how you can show some custom attributes for the selected item:

Example: 

ASPX Copy Code
<radcb:RadComboBox
          
id="RadComboBox1"
          
Runat="server"
          
OnClientSelectedIndexChanging="ItemChanged"
       
/>

<
script language="javascript">

function ItemChanged(item)
{
alert(item.Attributes.DisplayName);
  alert(item.Attributes.ImagePath);
}

</script>
        

See Also