asp.net – 当绑定到XmlDataSource时如何编程设置Dropdownlist的SelectedValue

我使用XmlDataSource作为下拉列表的数据源.

现在我想在页面初始加载时设置下拉列表的SelectedValue.我已经尝试了OnDataBound事件的下拉列表中,我可以看到总项目.但是设置SelectedValue不起作用. InOnDataBinding事件,我甚至看不到总项目可能是因为列表还没有绑定?

如何根据值设置所选索引?

解决方法

这似乎对我有用.
protected void Page_Load(object sender,EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DropDownList1.DataBind(); // get the data into the list you can set it
            DropDownList1.Items.FindByValue("SOMECREDITPROBLEMS").Selected = true;
        }
    }

相关文章

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