How to get items of DropdownList?

Hi,

   Is there a way to get the items of DropDownList?

Thanks,

3 Replies

PO Prince Oliver Syncfusion Team March 3, 2020 11:18 AM UTC

Hello J, 

Greetings from Syncfusion support. 

You can get the selected item in the DropDownList from the value property, or in the change event. Kindly refer to the following code. 

@using Syncfusion.EJ2.Blazor.DropDowns 
 
<EjsDropDownList TValue="string" TItem="Countries" @bind-Value="@dropValue" Placeholder="e.g. Australia" DataSource="@Country"> 
    <DropDownListFieldSettings Text="Name" Value="Code"></DropDownListFieldSettings> 
    <DropDownListEvents TValue="string" ValueChange="onchange"></DropDownListEvents> 
</EjsDropDownList> 
 
<div> 
    <span>Selected Item from bind-value :  @dropValue </span> 
</div> 
<div> 
    <span>Selected Item from change event :  @changeValue </span> 
</div> 
@code { 
 
    public string dropValue { get; set; } 
    public string changeValue { get; set; } 
 
    void onchange(ChangeEventArgs<string> args) 
    { 
        changeValue = args.Value; 
    } 
} 
  

Let us know if you need any further assistance on this. 

Regards, 
Prince 



J j March 3, 2020 11:21 AM UTC

Sorry for the confusion of the question, but I want is all the items inside the dropdownlist not just the selected one. Thank you.


PO Prince Oliver Syncfusion Team March 3, 2020 12:10 PM UTC

Hello J, 

You can get all the items inside the DropDownList from the DataSource property in the control. Kindly refer to the following code snippet 

@using Syncfusion.EJ2.Blazor.DropDowns 
 
<EjsDropDownList @ref="DropObj" TValue="string" TItem="Countries" Placeholder="e.g. Australia" DataSource="@Country"> 
    <DropDownListFieldSettings Text="Name" Value="Code"></DropDownListFieldSettings> 
</EjsDropDownList> 
 
<div> 
    <button @onclick="Getitems">Get items</button> 
</div> 
 
@if(Datalist != null) { 
    <div> 
        <ul> 
            @foreach (Countries item in Datalist) 
            { 
                <li> @item.Name </li> 
            } 
        </ul> 
    </div> 
} 
@code { 
 
    EjsDropDownList<string, Countries> DropObj; 
    public List<Countries> Datalist { get; set; } 
 
    void Getitems(MouseEventArgs args) 
    { 
        Datalist = this.DropObj.DataSource.ToList(); 
    } 
} 
  

Kindly check the above solution in your end and let us know if this meets your requirement. If not, kindly provide elaborate details on your use case or scenario. This will help us provide a prompt solution. 

Regards, 
Prince 


Loader.
Up arrow icon