Hello,
I'm unable to bind a RadzenCheckBoxList to an IEnumerable.
I found the Items property but I don't know how bind th RadzenCheckBoxListItem to MyObject property for text and value.
<RadzenCheckBoxList Items="MyObjectIEnumerable" Change="@(args => MyObejctChangeChanged(args, "Ambito"))">
In code:
protected IEnumerable MyObjectIEnumerable{ get; set; } = new List();
protected void MyObejctChangeChanged(IEnumerable value, string str)
{
... My CODE ...
}
Lorenzo Soncini
Italy
Hi @lorenzo,
Use a @foreach
<RadzenCheckBoxList>
<Items>
@foreach(MyItem item in Items)
{
<RadzenCheckBoxListItem
Text=@item.TextProperty Value=@item.ValueProperty />
}
</Items>
</RadzenCheckBoxList>
I receive the error "The child content property 'Items' is set by both the attribute and the element contents." when I try build the project.
My Code:
<RadzenCheckBoxList Items="MyObjectEnumerable" Change="@(args => MyObjectEnumerableChanged(args, "Ambito"))">
<Items>
@foreach (Library.EnumsString item in Items)
{
<RadzenCheckBoxListItem Text=@item.Descrizione Value=@item.Valore />
}
</Items>
</RadzenCheckBoxList>
Thanks
The error message describes the problem quite precisely. Delete the Items attribute as per my code example.
I have already tried and the error is:
CS0411 The type arguments for method TypeInference.CreateRadzenCheckBoxList_0(RenderTreeBuilder, int, int, EventCallback<IEnumerable>, int, RenderFragment)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
There is some place with working example?
I have solved. Is not able to use MyObject so I need specitfy TValue as string.
Working code:
<RadzenCheckBoxList TValue="string">
<Items>
@foreach (Library.MyObject item in MyObjectEnumerable )
{
<RadzenCheckBoxListItem Text=@item.Descrizione Value=@item.Valore />
}
</Items>
</RadzenCheckBoxList>
1 Like