el ninho
el ninho

Reputation: 4233

Get Value from ASPxComboBox get value

I have combobox with 2 values, ID and Name. I need to get ID from selected item, and I don't know how.

ASPxComboBox1.SelectedItem.GetValue(ID);

Not working.

Upvotes: 0

Views: 18456

Answers (4)

Soenhay
Soenhay

Reputation: 4048

ASPxComboBox1.TextField = "Name"; //This is the displayMember   
ASPxComboBox1.ValueField = "ID";  //This is the valueMember
ASPxComboBox1.ValueType = typeof(String);
ASPxComboBox1.DataSource = DataTableWithIDandNameColumns;
ASPxComboBox1.DataBind();

String theID = Convert.ToString(ASPxComboBox1.Value);//The column in the datasource that is specified by the ValueField property.
   OR:
String theID = Convert.ToString(ASPxComboBox1.SelectedItem.GetValue("ID"));//Any column name in the datasource.
   Also:
String theName = Convert.ToString(ASPxComboBox1.SelectedItem.GetValue("Name"));

Upvotes: 3

Mikhail
Mikhail

Reputation: 9300

Usually the problem, when the ASPxComboBox's SelectedItem / SelectedIndex is incorrect, occurs when the ASPxComboBox's ValueType http://documentation.devexpress.com/#AspNet/DevExpressWebASPxEditorsASPxComboBox_ValueTypetopic property is specified incorrectly.

Ensure that the ValueType is set, corresponding to the "Data Type Mappings (ADO.NET)" http://msdn.microsoft.com/en-us/library/cc716729.aspx table.

Upvotes: 0

Digbyswift
Digbyswift

Reputation: 10400

A combobox can only have one value per item and this is retrieved in your case by:

ASPxComboBox1.Value

See here in the documentation.

Since the value returned will be of type object, you will need to cast this to the type originally set, e.g. String. Then you will be able to work with it.

Upvotes: 0

Filip
Filip

Reputation: 3347

Use ASPxComboBox.Value property.

Upvotes: 1

Related Questions