Q:

How do I set the default value in select control?

0

This code will help you to understand how to set the default value in select control.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

The property value in the select control can be used to set the default value in the select control.

@page "/dropdown"

<select class="form-control" value="@defaultValue " @onchange="@OnSelect" style="width:150px">
       @foreach (var template in templates)
        {
     <option value=@template>@template</option>
         }
 </select>

<h5>@selectedString</h5>

@code {
List<string> templates = new List<string>() { "America", "China", "India", "Russia", "England" };
string selectedString = "";
string defaultValue = "India";
void OnSelect(ChangeEventArgs e)
{
       selectedString = "Selected Country is: " + e.Value.ToString();
}
    }

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now