2012-11-29 103 views
7

我使用:ASPxComboBoxASPxComboBox,如何設置選定的項目?

問題如何從代碼中設置了selectedValue背後?如果我的HTML這樣的:

<dxe:ASPxComboBox ID="cbxJobType" runat="server" width="200px" MaxLength="50"> 
        <Items> 
         <dxe:ListEditItem Text="Contract" Value="0" /> 
         <dxe:ListEditItem Text="Full Time" Value="1" /> 
         <dxe:ListEditItem Text="Part Time" Value="2" /> 
        </Items> 
        <ValidationSettings ErrorDisplayMode="ImageWithTooltip"> 
         <RequiredField ErrorText="Required Value" IsRequired="True" /> 
        </ValidationSettings> 
     </dxe:ASPxComboBox> 
+2

你爲什麼不直接接觸DX? – Mikhail

回答

21

客戶端腳本

給ClientInstanceName屬性comboBox訪問它的客戶端和ID屬性作爲cbxJobType訪問控制服務器端。

// by text 
    comboBox.SetText('Text #2'); 
    // by value 
    comboBox.SetValue('Value #2'); 
    // by index 
    comboBox.SetSelectedIndex(1); 

服務器端代碼

// by text 
cbxJobType.Text = "Text #2"; 
// by value 
cbxJobType.Value = "Value #2"; 
// by index 
cbxJobType.SelectedIndex = 1; 

此代碼工作太細:

cbxJobType.SelectedItem = cbxJobType.Items.FindByValue("Value #2"); 
3

您可以:

  • 設置ASPxComboBox.SelectedIndex財產;

  • 通過ASPxComboBox.Value財產及其價值選擇所需的項目:

代碼背後:

cbxJobType.SelectedIndex = 0; 
//or 
cbxJobType.Value = "0"; 
0

在客戶端,我發現有魯奇的建議的相當於:

cbxJobType.SelectedItem = cbxJobType.Items.FindByValue(「Value#2」);

那就是:

cbxJobType.SetSelectedItem(cbxJobType.FindItemByValue("Value #2")); 
// or 
cbxJobType.SetSelectedItem(cbxJobType.FindItemByText("Text #2")); 

轉到here瞭解更多關於ASPxComboBox在客戶端(ASPxClientComboBox)。

轉到here瞭解更多關於ASPxComboBox在服務器端。

那裏,你可以通過自己的所有成員,構造函數,事件和方法進行瀏覽。

0

你也可以看看下面的

cbxJobType.SelectedIndex = cbxJobType.Items.IndexOf(cbxJobType.Items.FindByValue("Value")); 

希望雖然這貼晚了,它可以幫助別人

相關問題