How to do bind-value blazor condition on RadzenDropDown?

Hi,

I am using a RadzenDropDown has multiple="true" on a common child component. And also I need to use the same RadzenDropDown have multiple="false" property in same child component. Can I do this? here is my dropdown

<RadzenDropDown class="form-control" placeholder="Select Category"
                        AllowClear="true"
                        AllowFiltering="true"
                        Multiple="true"
                        FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                        TextProperty="Name"
                        ValueProperty="Id"
                    @bind-Value=@idCategoryComma
                    Data = @_listCategory
                    Name="CategoryName"
                        Change=@(args => onProductsChange(args)) />
                    <RadzenRequiredValidator style="color:red; font-weight:bold;position: absolute;" Component="CategoryName" Text="Category is Required" />
@code{
[Required]
    public IEnumerable<string> idCategoryComma{ get; set; } = new List<string>();
    public string idCategory{ get; set; } = "";
  public bool IsMultiple { get; set; } = false;
    List<string> _listCategory;
}

Can I use like below code?

Multiple="@IsMultiple "
 @bind-Value="@(IsMultiple ?idCategoryComma:idCategory)"

No. Blazor two-way binging cannot be used with expressions.

1 Like

Means, the same RadzenDropDown, that have to apply property like multiple="false" we need to create new child component for this. Am I right sir?

Yes, you will need to use two different DropDown components if you plan to two-way bound the DropDown Value. In single selection the bound property should be single value of TValue type and in case of multiple selection should be IEnumerable.

2 Likes

Okay Sir! Thank you for you valuable reply.