c# - 获取一个asp :dropdownlist in code behind using C#的选中文本(不是选中值)

标签 c# asp.net code-behind

我需要读取嵌套在 FormView 中的下拉列表的 dataTextField 中所选文本(不是值)背后的代码。

这是我的 DDL:

<asp:DropDownList ID="DDL1" runat="server" DataSourceID="SQL1" dataTextField="name" DataValueField="IDname" CausesValidation="True" ClientIDMode="Static">
</asp:DropDownList>

下面是我的代码:

protected void UpdateButton_Click(object sender, EventArgs e)
{     
      DropDownList DDL1 = FV1.FindControl("DDL1") as DropDownList;
      SQL3.UpdateParameters["ddlparam"].DefaultValue = DDL1.SelectedValue;
     // Possible to get the text corresponding to the selectedValue?  
}

到目前为止一切顺利。现在我想获取与所选值对应的 dataTextField 中的文本。可能的?以及如何?

最佳答案

抓取所选项目的文本:

DDL1.SelectedItem.Text

关于c# - 获取一个asp :dropdownlist in code behind using C#的选中文本(不是选中值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31705388/

相关文章:

c# - 如何在 WPF 中正确绑定(bind)我的模型?

c# - 如何将过滤器应用于具有多个 "AND"条件的 DataView

asp.net - 防止在 ASP.Net 中重新提交表单(不重定向到我自己)

c# - 我应该在 DDD 域项目中验证吗?

c# - 如何将参数从 C# 传递到 MATLAB?

c# - 如何获取列表中多个列的总计并使用 LINQ 将其放入对象中?

c# - 提交修改viewstate所需的ajax asp表单

asp.net - 我可以将我的 .net 4.8 webforms webapp 升级到 .net 5.0 吗?

c# - 在代码隐藏 asp.net 中默认选中的复选框列表项

ASP.Net 在代码隐藏中启用跟踪