Skip to content

Latest commit

 

History

History
56 lines (46 loc) · 1.23 KB

radiogroup-bind-to-enum.md

File metadata and controls

56 lines (46 loc) · 1.23 KB
title description type page_title slug position tags ticketid res_type
Bind RadioGroup to an Enum
Is there a way to bind the Data source for a Blazor UI RadioGroup to an Enum?
how-to
Bind RadioGroup to an Enum
radiogroup-kb-enum-binding
radiogroup, binding, enum
1557229
kb

Environment

Product RadioGroup for Blazor

Description

Is there a way to bind the data source for a Blazor UI RadioGroup to an enum?

Solution

To achieve this, prepare a list of items that correspond to the enum values that can be shown to the user. Here is an example:

<TelerikRadioGroup @bind-Value="@Value" Data="@Subscriptions"></TelerikRadioGroup>

@code {
    private Subscription Value { get; set; }

    public enum Subscription
    {
        Day = 0,
        Week = 1,
        Month = 2,
        Year = 3
    }

    public List<Subscription> Subscriptions
    {
        get
        {
            var subscriptionsAsArray = (Subscription[])Enum.GetValues(typeof(Subscription));
            List<Subscription> subscriptions = new List<Subscription>(subscriptionsAsArray);

            return subscriptions;
        }
    }
}