简体   繁体   English

从ASPxComboBox获取价值获取价值

[英]Get Value from ASPxComboBox get value

I have combobox with 2 values, ID and Name. 我有两个值,ID和名称的组合框。 I need to get ID from selected item, and I don't know how. 我需要从所选项目中获取ID,但我不知道如何。

ASPxComboBox1.SelectedItem.GetValue(ID);

Not working. 不工作

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

使用ASPxComboBox.Value属性。

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, eg String . 由于返回的值将是object类型的,因此您需要将此值转换为最初设置的类型,例如String Then you will be able to work with it. 这样您就可以使用它了。

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. 通常,当错误地指定ASPxComboBox的ValueType http://documentation.devexpress.com/#AspNet/DevExpressWebASPxEditorsASPxComboBox_ValueTypetopic属性时,就会出现ASPxComboBox的SelectedItem / SelectedIndex错误的问题。

Ensure that the ValueType is set, corresponding to the "Data Type Mappings (ADO.NET)" http://msdn.microsoft.com/en-us/library/cc716729.aspx table. 确保已设置与“数据类型映射(ADO.NET)” http://msdn.microsoft.com/zh-CN/library/cc716729.aspx表相对应的ValueType。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM