ASPxComboBox - How to set selected item?

心已入冬 提交于 2019-11-30 19:26:27

Client-Side Script

Give ClientInstanceName property to comboBoxto access it client side and ID property as cbxJobType to access control 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 too:

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

You can either:

  • Set the ASPxComboBox.SelectedIndex property;

  • Select the required Item by its Value via the ASPxComboBox.Value property:

Code Behind:

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

On the client side, I found there is the equivalent of Ruchi's suggestion:

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

Which is:

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

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

Go here to learn more about the ASPxComboBox on the server side.

There you can browse through all their members, constructors, events and methods.

You can also look at the following

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

Hope though this is posted late, it may help someone else

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!