ASPxComboBox,如何设置所选项?

时间:2023-01-19 09:03:39

i'm using : ASPxComboBox

我正在使用:ASPxComboBox

problem is how to set selectedvalue from code behind? if my html like this :

问题是如何从代码后面设置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>

4 个解决方案

#1


23  

Client-Side Script

客户端脚本

Give ClientInstanceName property to comboBoxto access it client side and ID property as cbxJobType to access control server side.

将ClientInstanceName属性赋予comboBox以将其作为cbxJobType访问客户端和ID属性以访问控制服务器端。

 // 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");

#2


3  

You can either:

你可以:

  • Set the ASPxComboBox.SelectedIndex property;

    设置ASPxComboBox.SelectedIndex属性;

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

    通过ASPxComboBox.Value属性按其值选择所需的项:

Code Behind:

代码背后:

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

#3


1  

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

在客户端,我发现有相当于Ruchi的建议:

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

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).

转到此处以了解有关客户端ASPxComboBox的更多信息(ASPxClientComboBox)。

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

转到此处以了解有关服务器端ASPxComboBox的更多信息。

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

在那里,您可以浏览所有成员,构造函数,事件和方法。

#4


0  

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

希望虽然这是迟到的,但它可能会帮助别人

#1


23  

Client-Side Script

客户端脚本

Give ClientInstanceName property to comboBoxto access it client side and ID property as cbxJobType to access control server side.

将ClientInstanceName属性赋予comboBox以将其作为cbxJobType访问客户端和ID属性以访问控制服务器端。

 // 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");

#2


3  

You can either:

你可以:

  • Set the ASPxComboBox.SelectedIndex property;

    设置ASPxComboBox.SelectedIndex属性;

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

    通过ASPxComboBox.Value属性按其值选择所需的项:

Code Behind:

代码背后:

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

#3


1  

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

在客户端,我发现有相当于Ruchi的建议:

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

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).

转到此处以了解有关客户端ASPxComboBox的更多信息(ASPxClientComboBox)。

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

转到此处以了解有关服务器端ASPxComboBox的更多信息。

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

在那里,您可以浏览所有成员,构造函数,事件和方法。

#4


0  

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

希望虽然这是迟到的,但它可能会帮助别人