I am working on an Asp.NET project and I am trying to set the selected value of a dropdown list with a text property. For example i have i.e an item in the dropdown list with text test
. Programmatically can i set it to selecteditem
by Text
?. I am using the follwing code but is not working.
protected void Page_Load(object sender, EventArgs e)
{
string t = "test";
drpFunction.Text = t;
}
But is not working. Any suggestions ?
We can select text or we can also find the position of a text in a drop down list using option:selected attribute or by using val() method in jQuery. By using val() method : The val() method is an inbuilt method in jQuery which is used to return or set the value of attributes for the selected elements.
How to bind a selected item in a drop-down list to a text box and edit it? You can bind a selected value from the drop-down list using the ngModel and edit it inside the text box or numeric input box. The selected item text and value can be got using the change event of the drop-down list through the args. itemData.
1. Find the form you want to add the multi-select field to, select it and click Edit Form. 2. Under Template Form Fields, find the field and drag it into the canvas.
drpFunction.SelectedValue = drpFunction.Items.FindByText(t).Value;
This is better way to select text. By ioden's way it will show an error
"Multiple Items Cannot be selected in DropDownList"
string t = "test";
drpFunction.ClearSelection();
drpFunction.Items.FindByText(t).Selected = true;
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