We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Can the datasource just be a List<string>?

Can the Datasource be bound to a List<string> or does it have to be bound to a 'Dictionary' type class?  I get no items in the dropdown.

<EjsGrid DataSource="@EventList" Height="400" Toolbar="@gridToolbar">
......
        <GridColumn  HeaderText="Type" Width="80" EditType="EditType.DropDownEdit" DataSource="@eventTypes"></GridColumn>
        <GridColumn Field=@nameof(Events.Note) MaxWidth="200" HeaderText="Note" Width="120"></GridColumn>
        <GridColumn Field=@nameof(Events.EventId) HeaderText="ID" Width="120" Visible="false" IsPrimaryKey="true" IsIdentity="true"></GridColumn>
    </GridColumns>
</EjsGrid>


 eventTypes = config.GetSection("EventTypes").Get<List<string>>();

In my AppSettings:
 "EventTypes": [
    "Community",
    "Qualified",
    "Other"
  ]


4 Replies

VN Vignesh Natarajan Syncfusion Team October 9, 2019 11:27 AM UTC

Hi Michael,  

Greetings from Syncfusion support.  

Query: “Can the Datasource be bound to a List<string> or does it have to be bound to a 'Dictionary' type class?  I get no items in the dropdown. 

Yes, we need to bound the dataSource in form of Dictionary type (i.e.) Key and value pair for DropDownList control. We understand that you are facing issue while trying to display data in DropDownList inside the Grid column while editing. From your code example, we found that you have tried to bind the dataSource to Grid column instead of DropDownList. Hence the reported issue (Got no items in dropdown) occur. To resolve the reported issue, we suggest you to define the dataSource to DropDownList instead of grid columns using Edit params property of grid columns.  

Refer the below code example. 

<EjsGrid DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height="315"> 
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        <GridColumn HeaderText="Customer Name" EditType="EditType.DropDownEdit" Edit="@DropParams" Width="120"></GridColumn> 
        <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" EditType="EditType.DatePickerEdit" Format="yMd" TextAlign="TextAlign.Right" Width="130" Type="ColumnType.Date"></GridColumn> 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
    </GridColumns> 
</EjsGrid> 
 
@code{ 
    public static List<Order> Orders { get; set; } 
public static List<Countries> DDLData = new List<Countries> 
{ 
        new Countries() { Name = "Community", Code = "AU" }, 
        new Countries() { Name = "Qualified", Code = "BM" }, 
        new Countries() { Name = "Other", Code = "CA" },        
    }; 
    public object DropParams = new 
    { 
    @@params = new DropDownListModel<string> { DataSource = DDLData, Query = "new ej.data.Query()",Fields= new FieldSettingsModel() { Text = "Name" ,Value="Name" }  } 
    }; 


Refer the below screenshot for the output 

 

For your convenience we have prepared a sample which can be downloaded from below  
  

Note: In you code example, you have not defined Field property to DropDownList column, hence its value will not be saved or displayed in Grid.   

Refer our UG documentation for your reference 



Please get back to us if you have further queries.  

Regards, 
Vignesh Natarajan. 



ML Michael Lambert October 9, 2019 04:07 PM UTC

I find it rather astonishing that you cannot bind your DropDownList to a simple string[].  That should be basic functionality!!


VN Vignesh Natarajan Syncfusion Team October 10, 2019 04:36 AM UTC

Hi Michael, 

Query: “I find it rather astonishing that you cannot bind your DropDownList to a simple string[]. 
 
We have validated the defect you have initiated with us. Thank you for taking the time to report this issue “Not able to bind the dataSource as string[] / list<string> for dropdownlist column” and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle ) and including the defect fix in our next Nuget release which is expected to be roll out on or before 23rd October 2019.  
 
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link. 
 
 
Till then we appreciate your patience. 

Regards, 
Vignesh Natarajan. 



RS Renjith Singh Rajendran Syncfusion Team October 22, 2019 01:38 PM UTC

Hi Michael, 

We are glad to inform you that our latest Nuget package (17.3.0.19) has been successfully rolled out. In this release, we have included the fix for the issue “Not able to bind the dataSource as string[] / list<string> for dropdownlist column in Grid”. Please find the latest Nuget package from the link below, 

 
 
Also ensure to refer the latest version script and css in your application.  
 
     
    <link rel='nofollow' href="https://cdn.syncfusion.com/ej2/17.3.19/fabric.css" rel="stylesheet" /> 
 
 
Please get back to us if you have further queries. 

Regards, 
Renjith Singh Rajendran. 
 


Loader.
Live Chat Icon For mobile
Up arrow icon