ASPxComboBox - How to set the selected item?

I use: ASPxComboBox

The problem is how to set selectedValue from the code behind ? If my HTML is like this:

<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> 
+9
source share
4 answers

Client side Script

Grant the ClientInstanceName property for comboBoxto access to its client side and the ID property as cbxJobType for access to the management server side.

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

Server side code

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

This code works fine:

 cbxJobType.SelectedItem = cbxJobType.Items.FindByValue("Value #2"); 
+25
source

You can:

  • Set property ASPxComboBox.SelectedIndex ;

  • Select the required item by its value using the ASPxComboBox.Value property:

Code for:

 cbxJobType.SelectedIndex = 0; //or cbxJobType.Value = "0"; 
+3
source

On the client side, I found that there is the equivalent of a Ruchi offer:

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

What is:

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

Go here to learn more about ASPxComboBox on the client side (ASPxClientComboBox).

Go here to learn more about server side ASPxComboBox.

Here you can view all your members, constructors, events, and methods.

+1
source

You can also see the following

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

Hope this will be published late, this may help someone else

0
source

All Articles