Edit this page

Adding items programmatically

RadDropDownList supports adding items at run time, which means that you can manually populate it with data. The following example demonstrates how to add two different items to the RadDropDownList.Items collection.

You can use one of the following item types:

  • RadListDataItem – it represents a logical data item which can display specific text and image.

  • DescriptionTextListDataItem – similar to the RadListDataItem. In addition, it displays some description below the item’s text.

Figure 1: Sample RadListDataItem and DescriptionTextListDataItem

dropdown-and-listcontrol-dropdownlist-populating-with-data-adding-items-programmatically 001

Add items programmatically


DescriptionTextListDataItem descriptionItem = new DescriptionTextListDataItem();
descriptionItem.Text = "Chicken wings";
descriptionItem.Image = Properties.Resources.chicken_wings;
descriptionItem.DescriptionText = "some description";
this.radDropDownList1.Items.Add(descriptionItem);

RadListDataItem dataItem = new RadListDataItem();
dataItem.Text = "Chicken toast";
dataItem.Image = Properties.Resources.chicken_toast;
this.radDropDownList1.Items.Add(dataItem);

Dim descriptionItem As New DescriptionTextListDataItem()
descriptionItem.Text = "Chicken wings"
descriptionItem.Image = My.Resources.chicken_wings
descriptionItem.DescriptionText = "some description"
Me.radDropDownList1.Items.Add(descriptionItem)
Dim dataItem As New RadListDataItem()
dataItem.Text = "Chicken toast"
dataItem.Image = My.Resources.chicken_toast
Me.radDropDownList1.Items.Add(dataItem)

See Also