简体   繁体   中英

how to get selected text from html select in asp.net code-behind?

I use html Select in apsx page and bind it to data in database as dropdown:

<SELECT id="dd"  name="dd" runat="server" DataValueField="ID" DataTextField="Name">

Then in code behind, I can get the selected item value(which is mapped to ID) as:

myvalue = dd.value;

But I want to get the selected text(which is mapped to Name), not the value in code behind. How to do it?

试试这个dd.Items [dd.SelectedIndex] .Text

myvalue = dd.SelectedText;

编辑:对于数据绑定的htmlselect,您可以尝试:

myvalue = dd.DataSource[dd.SelectedIndex][dd.DataTextField].ToString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM