$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
How to Put up Items of Combobox Using C#
Home > How to > ComboBox Items
Using the ASP.NET AJAX ComboBox Control, users can set the item text, choose the image that is displayed on the item Text and define the text when mouse is over the item using C# code. Apart from these common properties, the web ComboBox Control also allows users to set the default item for custom validation. From this online tutorial, you will find sample C# codes which aim to show you how to customize the combobox item settings programmatically.

Set ComboBox Item Properties in C#

Here we list the properties that the ComboBox Control has offered and briefly illustrate the functions each property has owned.
  • Text: it means the text string that users can view in the drop-down list.
  • ToolTip: it controls the text string that appears when the mouse is over an item in the drop-down list.
  • Value: this property is a unique identifier for the item, which is used to define the value of SelectedValue property when an item is selected.
  • Selected: it is an indicator of whether the item is selected or not. And this property only allows users to select one item at a time. Therefore, if you set the Selected property of one item to true, then the Selected property of other items will be defined to false automatically. And if there is no item being selected, the Selected property of all items will be false.
  • Selected: it is an indicator of whether the item is selected or not. And this property only allows users to select one item at a time. Therefore, if you set the Selected property of one item to true, then the Selected property of other items will be defined to false automatically. And if there is no item being selected, the Selected property of all items will be false.
  • ImageUrl: you can use this property to define which image will be showed on the left of the item Text.
The C# programming example below is offered to guide you how to use above combobox item properties.
PerComboBoxItem item1 = new PerComboBoxItem();
item1.Text = "ASP.NET";
item1.Value = "ASP.NET";
item1.ToolTip = "ASP.NET";
item1.Selected = true;
item1.Enabled = true;
PerComboBox1.Items.Add(item1);

PerComboBoxItem item2 = new PerComboBoxItem();
item2.Text = "JQuery";
item2.Value = "JQuery";
item2.ToolTip = "JQuery";
item2.Selected = false;
item2.Enabled = false;
PerComboBox1.Items.Add(item2);

Set Default Item of ComboBox in C#

The Default Item property is mainly used for custom validation scenarios. The item that you set using the Default Item will be displayed as the first item in the drop-down list. Note: for easier validation, the value of the web ComboBox DOM object will return default item's value once the default item is selected.
Following sample C# code is used to show users how to use the Default Item property.
PerComboBox1.DefaultItem = new PerComboBoxDefaultItem();
PerComboBox1.DefaultItem.Text = "Please select item";
PerComboBox1.DefaultItem.Value = "-1";
ASP.NET AJAX UI Controls