asp.net – ASPxComboBox,如何设置所选项?

我正在使用: ASPxComboBox

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

解决方法

客户端脚本

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

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

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....