Click here to Skip to main content
15,845,565 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I have a
C#
RadzenDropDown
component and it's bind-Value should be set 'Zero' on page load.
C#
<RadzenDropDown AllowClear="true" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                        @bind-Value=@productValue Multiple="true" Placeholder="Select" Data=@listProduct TextProperty="Name" ValueProperty="Code"/>


What I have tried:

C#
List<Product> listProduct = new List<Product>();
 IEnumerable<string> productValue = new string[] { };
 protected override async Task OnInitializedAsync()
    {
listProduct.Add(new Product{ Code = "0", Name = "All" });
listProduct.Add(new Product{ Code = "1", Name = "Product1" });
listProduct.Add(new Product{ Code = "2", Name = "Product2" });
listProduct.Add(new Product{ Code = "3", Name = "Product3" });
productValue  = ("0").Split(new string[] { "," }, StringSplitOptions.None);
}


How can I write
C#
productValue = "0"
instead of
C#
productValue = ("0").Split(new string[] { "," }, StringSplitOptions.None);
?
Posted
Updated 24-Jul-23 8:34am
v2
Comments
Member 15627495 24-Jul-23 13:38pm    
IEnumerable<string> productValue = new string[]{"0"};

As it works by Vb .Net, it could help you.

1 solution

FIrstly, this line is a bit ... overcomplicated:
C#
varname = ("0").Split(new string[] { "," }, StringSplitOptions.None);
You can get the same result with
C#
varname = "0".Split(",", StringSplitOptions.None);
or
C#
varname = "0".Split(',', StringSplitOptions.None);
or even
C#
varname = "0".Split(',');

In fact, with a fixed string of "0" to Split on commas, what you get as a result is always going to be an array of strings containing a single element: "0"
But this code isn't what you want at all if you want a string in varname:
C#
IEnumerable<string> varname = myString.Split(myDelimiter);
Because while a string is an IEnumerable, it's an IEnumerable<char> not an IEnumerable<string>
If you write this:
C#
foreach (var x in "hello world!")
   ...
Then the type of x inside the loop will be char.

So you need to think about exactly what you expect the code to do, because in it's current state, it doesn't make any real sense at all!
 
Share this answer
 
v2
Comments
CPallini 24-Jul-23 2:52am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900