This is a migrated thread and some comments may be shown as answers.

Bind TelerikDropDownList to List of tuple

2 Answers 719 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Claudio
Top achievements
Rank 2
Bronze
Bronze
Iron
Claudio asked on 23 Mar 2021, 11:58 AM

I'm trying to bind a TelerikDropDownList to a list of tuple, but without success.  

 

<TelerikDropDownList Data="@Items" TextField="Text" ValueField="Value" @bind-Value="@Value"></TelerikDropDownList>

@code

{

   private List<(string Text, int Value)> Items { get; set; }

   private int Value {get;set;}

   protected override void OnInitialized()
   {
       base.OnInitialized();

 

      CreditSafeContractNotificationTypes = new List<(string Text, int Value)>()
      {
          ("Text1", 0),
          ("Text2", 1),
      };

   }

}

 

in chrome console i obtain this error:

 

 Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Telerik.Blazor.Components.TelerikDropDownList`2[[System.ValueTuple`2[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].<OnParametersSetAsync>b__57_1(ListDataItem item)
   at System.Linq.Enumerable.TryGetFirst[ListDataItem](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at System.Linq.Enumerable.FirstOrDefault[ListDataItem](IEnumerable`1 source, Func`2 predicate)
   at Telerik.Blazor.Components.TelerikDropDownList`2.<OnParametersSetAsync>d__57[[System.ValueTuple`2[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
   at Telerik.Blazor.Components.Common.TelerikSelectBase`2.<SetParametersAsync>d__133[[System.ValueTuple`2[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()

 

What's wrong?

Thanks

2 Answers, 1 is accepted

Sort by
0
Claudio
Top achievements
Rank 2
Bronze
Bronze
Iron
answered on 23 Mar 2021, 06:12 PM

wrong code paste, replace CreditSafeContractNotificationTypes with Items

the problem still remain

0
Marin Bratanov
Telerik team
answered on 24 Mar 2021, 05:54 PM

Hello Claudio,

The DropDownList component supports binding to a list of primitive values (numbers, strings, guids, enums), or to an instance of a model. You can find these two approaches in the following article: https://docs.telerik.com/blazor-ui/components/dropdownlist/data-bind. A tuple is not a supported data type that the component can use.

 

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
General Discussions
Asked by
Claudio
Top achievements
Rank 2
Bronze
Bronze
Iron
Answers by
Claudio
Top achievements
Rank 2
Bronze
Bronze
Iron
Marin Bratanov
Telerik team
Share this question
or