1

I'm trying to get the text from the selected value in the combo box by using:

lblMessage.Text = cmbArchivoModificado.SelectedItem.Text;

I've already set the valuefield and textfield on the combobox settings, but visual studio keep telling me this:

nullreferenceException was unhandled by user code.

Object reference not set to an instance of an object.

Community
  • 1
  • 1

3 Answers3

2

Usually the problem, when the ASPxComboBox's SelectedItem / SelectedIndex is incorrect, occurs when the ASPxComboBox.ValueType property is specified incorrectly.

Ensure that the ValueType is set, corresponding to the "Data Type Mappings (ADO.NET)" table.

Try to use the ASPxComboBox.Value property instead:

lblMessage.Text = cmbArchivoModificado.Value != null
     ?  cmbArchivoModificado.Value.ToString()
     :  string.Empty;
Mikhail
  • 9,186
  • 4
  • 33
  • 49
0

Looks to me like you need to first check whether cmbArchivoModificado.SelectedItem is null.

lblMessage.Text = cmbArchivoModificado.SelectedItem == null ? "NA" 
    : cmbArchivoModificado.SelectedItem.Text;
Vyskol
  • 298
  • 3
  • 11
0

Get the value on this way:

var value = comboboxExample.SelectecText;

or

var value = comboboxExample.EditValue;
xbral
  • 91
  • 4