in my data model I have records that also (among others) have an INT field storing values from 0..2 for each record. The INT value represents a certain value which is not declared (no FK) as a separate type/entity in the data model. In my case the (implicit) meaning is:
0 = None
1 = Some
2 = All
When creating a page in Radzen and binding to my datamodel, by default an "Numeric" control is created that shows the INT value.
Now, I want to show the user a dropdown instead that shows the values "None", "Some" and "All" and internally maps these values to the data property (INT).
I created a page property of type List which I assign to: new List() {"None", "Some", "All"} and bound this to the Data property of a Dropdown control. This works, but how can I now map the ValueProperty of the Dropdown to the INT data property of my current data record?
In Lightswitch there was an easy way to create a static table for dropdowns that holds the data values (0..1) mapped with the string values ("None","Some","All") for display to do this.
Any ideas how this can easily be done directly in Radzen IDE?
thanks for your quick reply. Not quite sure if I got your approach right: if I change List to List, I get an error telling me that type "System.Collections.Generic.List" cannot implicitly be converted to "System.Collections.Generic.IEnumerable".
Can you give me some more details on how to set up this mapping?
The Data property must contain the list of available items but how do I set TextProperty and ValueProperty? My data record uses an INT. Or do I leave "Data" property of the Dropdown blank in this case?
new List(){new MyObject(){Id = 1, Text = “YourText”}}.
Check our demos for reference - all examples are using TextProperty and ValueProperty. What saves the chosen value is @bind-Value=“dataItem.YourProperty”
Thanks for your help. I think I have come closer to solving this now.
In the "Pagename.razor.cs" I declared a helper class like this:
public class DropdownValue
{
public int Id { get; set; }
public string Name { get; set; }
}
Now, in the Page Load Handler, I do a "Set property" with:
Name: Statuses
Value: new List(){new DropdownValue(){Id = 0, Name="A"}, new DropdownValue(){Id = 1, Name="B"}, new DropdownValue(){Id = 2, Name="C"}}
Property type: IEnumerable
In the page, it place a Dropdown control and set the following properties:
TextProperty: Name
ValueProperty: Id
Data: ${Statuses}
Value: ${mycurrentrecord.Status}
where Status is an INT property from the data model.
The dropdown now shows the correct values I can select from ("A", "B", "C") but it seems as if it does not bind this to the data model. Initially, the selected item of the dropdown is empty and if I make any changes to it, it has no effect on the data of the selected record. However, if I add a Numeric and bind it's value to ${mycurrentrecord.Status} I can see/edit the value from the data record.
This approach is working. I don't know why but when I restarted Radzen and ran again, it works as it should. Thanks again for your excellent and quick help!