2011-12-23 4 views
0

나는 combobox에 2 개의 값, ID 및 이름이 있습니다. 선택한 항목에서 ID를 가져와야하고 어떻게해야할지 모르겠다.ASPxComboBox에서 값 가져 오기

ASPxComboBox1.SelectedItem.GetValue(ID); 

작동하지 않습니다.

+0

@DenysWessels 그것은 Combobox이고 Devexpress입니다. –

+0

** http : //documentation.devexpress.com/#AspNet/DevExpressWebASPxEditorsScriptsASPxClientEditBase_GetValuetopic** –

+0

에서보세요. 콤보 상자 코드를 게시하십시오. 해결책을 찾는 것이 훨씬 더 쉬울 것입니다. – Filip

답변

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

콤보 상자는 항목 당 하나 개의 값을 가질 수 있으며이하여 경우에 검색됩니다 :

ASPxComboBox1.Value 

여기 documentation에서 참조하십시오.

반환되는 값의 유형은 object이므로 원래 설정된 유형으로이 값을 캐스팅해야합니다. 예 : String. 그러면 그걸로 일할 수있을거야.

+0

테이블의 데이터를 바인드하면 많은 데이터가있을 수 있습니다. 테이블을 두 줄로 묶었습니다. –

+0

아니요, 항목은 하나의 값만 가질 수 있습니다. 컨트롤은 여러 항목을 가질 수 있으며 각 항목은 Value 속성에 대해 설정된 하나의 개체 만 가질 수 있습니다. 항목의 Value 속성에 테이블을 바인딩 할 수 있지만 항목에는 여전히 하나의 Value 속성 만 있습니다. – Digbyswift

+0

좋아요. 가치가있는 열을 선택하는 방법에 대한 아이디어가 있습니까? 감사. –