How can I set the selected value of a Select
HTML control from a code-behind file using ASP.NET and C#?
There are FindByText
and FindByValue
functions available:
ListItem li = Select1.Items.FindByText("Three");
ListItem li = Select1.Items.FindByValue("3");
li.Selected = true;
HTML:
<select id="selUserFilterOptions" runat="server">
<option value="1">apple</option>
<option value="2">orange</option>
<option value="3">strawberry</option>
</select>
C#:
string fruitId = selUserFilterOptions.Value.ToString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With