KentZhou
KentZhou

Reputation: 25573

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?

Upvotes: 0

Views: 12752

Answers (2)

Nav
Nav

Reputation: 86

try this dd.Items[dd.SelectedIndex].Text

Upvotes: 6

Joel Etherton
Joel Etherton

Reputation: 37543

myvalue = dd.SelectedText;

Edit: For a databound htmlselect you can try:

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

Upvotes: 2

Related Questions