A newer version of this page is available. Switch to the current version.

How to: Bind ASPxComboBox Manually

In certain cases, you may need to manually bind ASPxComboBox to a data source. For this purpose, handle the ASPxComboBox.Init event:

<dx:ASPxComboBox ID="ASPxComboBox1" runat="server" ... OnInit="OnComboBoxInit">

Then, choose one of the following solutions:

If you wish to bind ASPxComboBox when the page is loaded for the first time and save the collection in a view state, utilize the following code:

public void OnComboBoxInit(object sender, EventArgs e) {
     if(!IsCallback && !IsPostBack) 
          (sender as ASPxComboBox).DataBind();
}

If you do not wish to bind ASPxComboBox when the page is loaded for the first time and keep the collection in the view state, rebind ASPxComboBox on each round-trip to the server:

public void OnComboBoxInit(object sender, EventArgs e) {
     if(IsCallback || IsPostBack)
          (sender as ASPxComboBox).DataBind();
}