This example shows how to load combo box items on the first click of the drop-down button.
In this example, the ASPxComboBox control initially has one (default) item.
private const string DefaultCountryName = "United Kingdom";
protected void Page_Load(object sender, EventArgs e) {
if(!IsCallback) {
cbCountries.Items.Add(DefaultCountryName);
cbCountries.SelectedIndex = 0;
}
}
When the drop-down button is clicked, the DropDown event handler sends a callback to the server if the items are not loaded yet.
function OnDropDown(s, e) {
if(!s.countriesLoaded) {
s.countriesLoaded = true;
cbCountries.PerformCallback();
}
}
The PerformCallback method invokes the server Callback event. The event handler populates the Items collection with a list of items.
protected void OnCallback(object source, CallbackEventArgsBase e) {
List<string> counties = new List<string>(DataProvider.GetCountries());
counties.Remove(DefaultCountryName);
((ASPxComboBox)source).Items.AddRange(counties);
}
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
- Countries.xml (VB: Countries.xml)
- DataProvider.cs (VB: DataProvider.vb)
(you will be redirected to DevExpress.com to submit your response)