Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
148195 | Oct 9,2019 06:14 PM UTC | Nov 5,2019 04:47 PM UTC | Blazor | 5 |
![]() |
Tags: ListBox |
<EjsListBox DataSource="@SignedUp" TValue="string[]" ModelType="Model">
<ListBoxFieldSettings Text="Text" Value="Value" />
<ListBoxEvents TValue="string[]"></ListBoxEvents>
</EjsListBox>
<input type="button" @onclick="@ChangeData" value="Add data" />
@code{
public ObservableCollection<ListData> SignedUp { get; set; }
ListData Model = new ListData();
int currentCount = 5;
public void ChangeData()
{
currentCount++;
this.SignedUp.Add(new ListData() { Text = "AddedItem" + currentCount, Value = "Item" + currentCount });
}
protected override void OnInitialized()
{
this.SignedUp = ListData.getListData();
}
public class ListData
{
public string Text { get; set; }
public string Value { get; set; }
public static ObservableCollection<ListData> getListData()
{
ObservableCollection<ListData> data = new ObservableCollection<ListData>();
data.Add(new ListData() { Text = "Hennessey Venom", Value = "Item1" });
data.Add(new ListData() { Text = "Bugatti Chiron", Value = "Item2" });
data.Add(new ListData() { Text = "Bugatti Veyron Super Sport", Value = "Item3" });
data.Add(new ListData() { Text = "SSC Ultimate Aero", Value = "Item4" });
data.Add(new ListData() { Text = "Koenigsegg CCR", Value = "Item5" });
return data;
}
}
} |
<EjsListBox DataSource="@SignedUp" TValue="string[]" ModelType="Model" @ref="listbox">
<ListBoxFieldSettings Text="Text" Value="Value" />
<ListBoxSelectionSettings ShowCheckbox="true"></ListBoxSelectionSettings>
<ListBoxEvents TValue="string[]" ValueChange="onValueChange"></ListBoxEvents>
</EjsListBox>
<p>@Items</p>
<input type="button" @onclick="@ChangeData" value="Add data" />
<input type="button" @onclick="@ToGetData" value="Get Selected data" />
@code{
EjsListBox<string[]> listbox;
public ObservableCollection<ListData> SignedUp { get; set; }
ListData Model = new ListData();
public List<ListData>selectedItems;
public string Items;
int currentCount = 5;
public void ChangeData()
{
currentCount++;
this.SignedUp.Add(new ListData() { Text = "AddedItem" + currentCount, Value = "Item" + currentCount });
}
public void ToGetData()
{
Items = JsonConvert.SerializeObject(selectedItems); // Display the selected items
this.StateHasChanged();
}
public void onValueChange(Syncfusion.EJ2.Blazor.DropDowns.ListBoxChangeEventArgs args)
{
selectedItems = ((JArray)args.Items).ToObject<List<ListData>>(); // Get the selected items in ValueChange event
}
protected override void OnInitialized()
{
this.SignedUp = ListData.getListData();
}
public class ListData
{
public string Text { get; set; }
public string Value { get; set; }
public static ObservableCollection<ListData> getListData()
{
ObservableCollection<ListData> data = new ObservableCollection<ListData>();
data.Add(new ListData() { Text = "Hennessey Venom", Value = "Item1" });
data.Add(new ListData() { Text = "Bugatti Chiron", Value = "Item2" });
data.Add(new ListData() { Text = "Bugatti Veyron Super Sport", Value = "Item3" });
data.Add(new ListData() { Text = "SSC Ultimate Aero", Value = "Item4" });
data.Add(new ListData() { Text = "Koenigsegg CCR", Value = "Item5" });
return data;
}
}
} |
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.
This page will automatically be redirected to the sign-in page in 10 seconds.