Binding Enum data to DropDownList in Razor pages

Hi, 

I was wondering what is the easiest way to bind the Enum data to DropDownList in DataGrid?

Grid:

<e-grid-column field="Status" headerText="Status" editType="dropdownedit" width="120"> </e-grid-column>

Enum model:

public enum Status
    {
        [EnumMember(Value = "Delivery")]
        Delivery = 0,
        [EnumMember(Value = "Warehouse")]
        Warehouse = 1,
        [EnumMember(Value = "Drying")]
        Drying = 2,
        [EnumMember(Value = "Dried")]
        Dried = 3,
        [EnumMember(Value = "Cutting")]
        Cutting = 4,
        [EnumMember(Value = "Cutted")]
        Cutted = 5
    }



4 Replies

RS Rajapandiyan Settu Syncfusion Team February 7, 2022 01:03 PM UTC

Hi Miha, 

Thanks for contacting Syncfusion support. 

Currently, we are validating this query (“I was wondering what is the easiest way to bind the Enum data to DropDownList in DataGrid”) at our end and will update the further details on or before Feb 9th, 2022. 

We appreciate your patience until then. 

Regards, 
Rajapandiyan S 



RS Rajapandiyan Settu Syncfusion Team February 10, 2022 12:56 PM UTC

Hi Miha, 

Thanks for your patience. 

We have validated your query and checked with our end. By default .Net core application returns enum values(int) instead of names. We can return the Enum string by using following way, 


public class OrdersDetails 
{ 
    public int? OrderID { get; set; } 
    [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] 
    public state State { get; } 
} 
public enum state 
{ 
    [EnumMember(Value = "Delivery")] 
    Delivery = 0, 
    [EnumMember(Value = "Warehouse")] 
    Warehouse = 1, 
    [EnumMember(Value = "Drying")] 
    Drying = 2, 
    [EnumMember(Value = "Dried")] 
    Dried = 3, 
    [EnumMember(Value = "Cutting")] 
    Cutting = 4, 
    [EnumMember(Value = "Cutted")] 
    Cutted = 5 
} 



Please get back to us if you need further assistance. 

Regards, 
Rajapandiyan S 



MI Miha replied to Rajapandiyan Settu February 10, 2022 10:31 PM UTC

Hi Rajapandiyan,

tnx for the example, however this example only works if the table is already populated. If the table is not populated the example does not work.


Populated table:



Unpopulated table:



Because only two records exist in the table it returns only two options. But I want to return the list where you could select from all options.

I guess I need to bind the data using URL adaptor?


Thank you for your support, Miha




BS Balaji Sekar Syncfusion Team February 11, 2022 04:38 PM UTC

Hi Miha, 

Based on your query, we can bind the custom dataSource to dropdown edit type column using cell edit params option it will help to enable the input component properties/events and it will perform in the edit mode. We already discussed in our documentation as below. 

Please refer the below link for more information. 


Regards, 
Balaji Sekar. 


Loader.
Up arrow icon