在使用C#编写的后端代码中获取asp:dropdownlist中已选文本(非选定值)

3

我需要在代码中读取嵌套在FormView中的下拉列表(dropdownlist)的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中的文本。这可能吗?如何实现?


2
使用DDL1.SelectedItem.Text。 - Enrique Zavaleta
2个回答

4

使用以下代码获取所选项目的文本:

DDL1.SelectedItem.Text

3

你正在寻找 DDL.SelectedItem.Text,请参考MSDN文档


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接