LanaDX / how-to-load-items-into-the-aspxcombobox-on-a-callback-e1426

.NET, ASP.NET Web Forms, ASPxDataEditors

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Combo Box for ASP.NET Web Forms - How to load items on a callback

[Run Online]

This example shows how to load combo box items on the first click of the drop-down button.

Combo box

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);
}

Files to Review

Documentation

About

.NET, ASP.NET Web Forms, ASPxDataEditors

License:Other


Languages

Language:C# 60.0%Language:Visual Basic .NET 23.4%Language:ASP.NET 16.7%