我有两个值的combobox,ID和Name。我需要从选定的项目中获取ID,但我不知道如何获取。
ASPxComboBox1.SelectedItem.GetValue(ID);不起作用。
发布于 2012-08-28 22:46:13
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"));发布于 2011-12-23 19:28:57
使用ASPxComboBox.Value属性。
发布于 2011-12-23 19:29:46
combobox的每个项目只能有一个值,在您的情况下可以通过以下方式检索:
ASPxComboBox1.Value请在documentation中查看此处。
由于返回的值将是object类型,因此您需要将其强制转换为最初设置的类型,例如String。然后你就可以使用它了。
https://stackoverflow.com/questions/8615468
复制相似问题