我需要读取嵌套在 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/