We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to get selected value in Blazor Dropdown List?

Answer:


When a value is selected from a DropDown List, the OnValueSelect event is triggered. We can obtain the value by using that event. Please refer the code snippet below.


<SfDropDownList TItem="GameFields" TValue="string" PopupHeight="230px" Placeholder="Select a game" @bind-Value="@DropVal" DataSource="@Games">

<DropDownListEvents TValue="string" ValueChange="OnChange" OnValueSelect="onSelect">DropDownListEvents>

<DropDownListFieldSettings Text="Text" Value="ID">DropDownListFieldSettings>

SfDropDownList>



2 Replies

KG khalid ghoddane December 15, 2021 09:02 PM UTC

 Hi! 
Basically when the value get changed in the dropdown , it get passed inside the ChangeEventArgs e . 
so if you wanna make an event as OnValueSelect and implement a function for it 
first you have to make the function take a parameter of the type you wanna get from the dropDown . 
for example if the value type is string then you will make the function take a string parameter . 
and it will be like : 

<SfDropDownList TItem="GameFields" TValue="string" PopupHeight="230px" Placeholder="Select a game" @bind-Value="@DropVal" DataSource="@Games">

<DropDownListEvents TValue="string" ValueChange="OnChange" OnValueSelect="@((e)=>OnSelect(e.value))">DropDownListEvents>

<DropDownListFieldSettings Text="Text" Value="ID">DropDownListFieldSettings>

SfDropDownList>


@{

public void  OnSelect( string e ) 

{

// here u can use the e to do what u want

}


}


also i degust using ValueChange rather then OnValueSelect.



BC Berly Christopher Syncfusion Team December 16, 2021 01:39 PM UTC

Hi Khalid Ghoddane, 
  
Thanks for sharing your suggestion to us. Please let us know if you need further assistance on this. 
  
Regards, 
Berly B.C 
 


Loader.
Up arrow icon