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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Update DropDownList Items dynamically

Thread ID:

Created:

Updated:

Platform:

Replies:

146346 Aug 1,2019 02:03 AM UTC Aug 2,2019 02:01 PM UTC Blazor 3
loading
Tags: Dropdown List
Oswaldo Raul Diaz Guzman
Asked On August 1, 2019 02:03 AM UTC

Hi, I can't update DropDownList Items dynamically, is there any way it can be accomplished?


Thanks

Sevvandhi Nagulan [Syncfusion]
Replied On August 1, 2019 10:19 AM UTC

Hi Oswaldo, 
  
Greetings from Syncfusion support.  

Yes, it can be accomplished by using our public method AddItem. We Added the new items in DropDownList items by clicking the button as mentioned below, 

[Index.razor] 
   <div> 
    <EjsDropDownList @ref="@DropDownObj" Placeholder="Select a game" DataSource="@LocalData"> 
        <DropDownListFieldSettings Value="ID" Text="Text"></DropDownListFieldSettings> 
    </EjsDropDownList> 
</div> 
<div> 
    <input type="button" value="AddItem" onclick="@AddItems" /> 
</div> 
 
@code { 
    EjsDropDownList DropDownObj; 
    public class Games 
    { 
        public string ID { get; set; } 
        public string Text { get; set; } 
    } 
    List<Games> LocalData = new List<Games> { 
    new Games() { ID= "Game1", Text= "American Football" }, 
    new Games() { ID= "Game2", Text= "Badminton" }, 
    new Games() { ID= "Game3", Text= "Basketball" }, 
    new Games() { ID= "Game4", Text= "Cricket" } 
  }; 
    public List<Games> Item = new List<Games>{ 
    new Games() { ID= "Game6", Text= "Golf" } 
   }; 
public void AddItems() 
{ 
    this.DropDownObj.AddItem(Item); 
} 
} 

  
Note: We're working on giving Observable collection DataSource support in blazor, so once it's rolled out we can add the item directly into DataSource(It will be included in Today’s Release). 
  
Please find the sample below, 


Regards, 
Sevvandhi N 


Oswaldo Raul Diaz Guzman
Replied On August 1, 2019 04:12 PM UTC

Thanks so much, I've been using and recomending Synfusion for years an I'm very happy working with Syncfusion's blazor components.



Sevvandhi Nagulan [Syncfusion]
Replied On August 2, 2019 02:01 PM UTC

Hi Oswaldo, 

Most welcome. 
  
We are glad to announce that our latest patch release in the version 17.2.0.40-beta has been rolled out successfully and in that release, we have included the “Observable collection data binding support”. 
 
Import the ObjectModel from collections and change the List type to ObservableCollection type. You can then add the items directly to DataSource as shown below.  
 
[Index.razor] 
@using System.Collections.ObjectModel; 
<div> 
    <EjsDropDownList Placeholder="Select a game" DataSource="@LocalData" TValue="string"> 
        <DropDownListFieldSettings Value="ID" Text="Text"></DropDownListFieldSettings> 
    </EjsDropDownList> 
</div> 
<div> 
    <input type="button" value="AddItem" onclick="@AddItems" /> 
</div> 
 
@code {  
    public class Games 
    { 
        public string ID { get; set; } 
        public string Text { get; set; } 
    } 
    ObservableCollection<Games> LocalData = new ObservableCollection<Games> { 
    new Games() { ID= "Game1", Text= "American Football" }, 
    new Games() { ID= "Game2", Text= "Badminton" }, 
    new Games() { ID= "Game3", Text= "Basketball" }, 
    new Games() { ID= "Game4", Text= "Cricket" } 
  }; 
     
public void AddItems() 
{ 
    this.LocalData.Add(new Games() { ID= "Game6", Text= "Golf" }); 
} 
} 


Please find the NuGet from the below link. 



Please find the release notes details from the below link. 


Please find the sample below, 

 

Regards, 
Sevvandhi N 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon