@using Syncfusion.EJ2.Blazor.DropDowns;
<EjsDropDownList TValue="int?" TItem="ExpandoObject" ID="ctl1" Placeholder="Select..." ShowClearButton="true" DataSource="@DataSource2">
<DropDownListFieldSettings Text="Text" Value="ID"></DropDownListFieldSettings>
</EjsDropDownList>
@code {
public List<ExpandoObject> DataSource2 { get; set; } = new List<ExpandoObject>();
protected override void OnInitialized()
{
for (int i = 1; i <= 10; i++)
{
ExpandoObject expando = new ExpandoObject();
expando.ID = i;
expando.Text = $"Text..{i}";
DataSource2.Add(expando);
}
}
public class ExpandoObject
{
public int ID { get; set; }
public string Text { get; set; }
}
} |
<div id="component-container">
@DynamicRender
</div>
<EjsButton ID="dynamic-button" Content="Render DropDownList" @onclick="RenderComponent"></EjsButton>
@code {
private RenderFragment DynamicRender { get; set; }
public string value { get; set; }
public List<ExpandoObject> DataSource2 { get; set; } = new List<ExpandoObject>();
private RenderFragment CreateComponent() => builder =>
{
builder.OpenComponent(0, typeof(EjsDropDownList<string, ExpandoObject>));
builder.AddAttribute(1, "Value", value);
builder.AddAttribute(2, "DataSource", DataSource2);
builder.AddAttribute(3, "ShowClearButton", true);
builder.AddAttribute(4, "ChildContent", (Microsoft.AspNetCore.Components.RenderFragment)((builder2) =>
{
builder2.AddMarkupContent(5, "\r\n ");
builder2.OpenComponent<Syncfusion.EJ2.Blazor.DropDowns.DropDownListFieldSettings>
(6);
builder2.AddAttribute(7, "Value", "ID");
builder2.AddAttribute(8, "Text", "Text");
builder2.CloseComponent();
builder2.AddMarkupContent(9, "\r\n");
}));
builder.CloseComponent();
};
private void RenderComponent()
{
DynamicRender = CreateComponent();
}
protected override void OnInitialized()
{
for (int i = 1; i <= 10; i++)
{
ExpandoObject expando = new ExpandoObject();
expando.ID = i;
expando.Text = $"Text..{i}";
DataSource2.Add(expando);
}
}
public class ExpandoObject
{
public int ID { get; set; }
public string Text { get; set; }
}
} |