Can't Bind DropDownList to GridColumn where DataSource is a List of CustomTypes
We use strongly typed enums for all of our enumerations.


Attachment: SampleApp_4bb60529.zip
I am trying to bind such a type list to a datagrid column and am not having much luck.
I have attached a working Blazor server project that has the grid within in it.
Here is the data grid. The PointOfExecution type is a strongly typed enum.
Add New Row Scenario
- Press Add - New empty row shows up.
- Enter Data and press Update
- Saved row is setting the PointOfExection to Null
Editing Scenario
- Double click row to put into edit mode. Note: lost the PointOfExecution name
- Modify Data and press Update
- Will not save changes
Attachment: SampleApp_4bb60529.zip
SIGN IN To post a reply.
5 Replies
1 reply marked as answer
RS
Renjith Singh Rajendran
Syncfusion Team
October 30, 2020 12:15 PM UTC
Hi John,
Greetings from Syncfusion support.
We suggest you to ensure to enable a IsPrimaryKey column in Grid. And also, ensure to provide proper property values for the SfDropDownList rendered inside the EditTemplate to overcome the problem you are facing. We have also modified the sample for your reference, please download the modified sample form the link below,
References :
Please refer the below highlighted codes, and use these codes in your application to overcome the problem you are facing.
... |
Please get back to us if you need further assistance.
Regards,
Renjith Singh Rajendran
Marked as answer
JO
John
October 30, 2020 12:20 PM UTC
Thank you Renjith for your prompt reply. Very much appreciate that.
Setting the RuleName to primary key works just fine for me as I do wish these names to remain unique but how does setting the IsPrimaryKey factor into properly setting up a drop-down list?
Is it just for good practice or is it necessary to support drop-downs within the grid in general?
JO
John
October 30, 2020 12:39 PM UTC
Actually never mind, I now understand why setting a the RuleName to IsPrimary... it is necessary so that when you commit the Update that it can update the row that is under edit. Makes perfect sense.
JO
John
October 31, 2020 03:59 PM UTC
When I change to Dialog from Normal editing in the Data Grid I am not able to edit Rule Name and Description fields in Dialog mode when adding new record. I can change the 3 drop downs, just can't modify Rule Name or Description fields. Only in Dialog mode. I can edit all fields when in Normal edit mode.


<SfGrid @ref="AggRules" DataSource="@SelectedDomainRule.BusinessRuleDefinition.AggregateRuleSources" TValue="AggregateRuleSource" ID="AggregateRules"
Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })"
AllowPaging="true" AllowSorting="true" AllowSelection="true">
<GridEvents RowSelected="RowSelectHandler" TValue="AggregateRuleSource"></GridEvents>
<GridPageSettings PageSize="10"></GridPageSettings>
<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Normal"></GridEditSettings>
<GridColumns>
<GridColumn Field="AggregateRuleSource_Id" IsPrimaryKey="true" IsIdentity="true" Width="20"></GridColumn>
<GridColumn Field="RuleName" HeaderText="Rule Name" Width="20"></GridColumn>
<GridColumn Field="RuleDescription" HeaderText="Description" Width="15"></GridColumn>
<GridColumn Field="PointOfExecution.Name" HeaderText="PointOfExecution" EditType="EditType.DropDownEdit" Width="30">
<EditTemplate>
@*ID value should be based on Field name*@
<SfDropDownList ID="PointOfExecution___Name"
TItem="PointOfExecution"
TValue="string"
@bind-Value="@((context as AggregateRuleSource).PointOfExecution.Name)"
DataSource="@PointOfExecution.Values">
<DropDownListFieldSettings Text="Name" Value="Name"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
<GridColumn Field="RuleStatus.Name" HeaderText="Rule Status" EditType="EditType.DropDownEdit" Width="30">
<EditTemplate>
@*ID value should be based on Field name*@
<SfDropDownList ID="RuleStatus___Name"
TItem="RuleStatus"
TValue="string"
@bind-Value="@((context as AggregateRuleSource).RuleStatus.Name)"
DataSource="@RuleStatus.Values">
<DropDownListFieldSettings Text="Name" Value="Name"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
<GridColumn Field="RuleType.Name" HeaderText="Rule Type" EditType="EditType.DropDownEdit" Width="30">
<EditTemplate>
@*ID value should be based on Field name*@
<SfDropDownList ID="RuleType___Name"
TItem="RuleType"
TValue="string"
@bind-Value="@((context as AggregateRuleSource).RuleType.Name)"
DataSource="@RuleType.Values">
<DropDownListFieldSettings Text="Name" Value="Name"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid>
Why is that ?
RS
Renjith Singh Rajendran
Syncfusion Team
November 2, 2020 08:40 AM UTC
Hi John,
Thanks for your update.
We tried reproduce the reported problem by creating a sample based on the shared codes. But we could not face the reported problem with the sample from our side. We could edit the RuleName and RuleDescription columns in the Add form. We are attaching the sample for your reference, please download the sample from the link below,
Please refer the above attached sample and if you are still facing difficulties, then the following details would be helpful for us to proceed further.
- Share the sample which you have tried form your side.
- Or if possible, reproduce the problem with the attached sample and share with us for further analysis.
- Share the exact scenario, or proper replication procedure.
- Share a video demo showing the replication procedure of the problem you are facing.
- Share the details of exception or error if any occurred in the browser console.
The provided information will help us analyze the problem, and provide you a solution as early as possible.
Regards,
Renjith Singh Rajendran
SIGN IN To post a reply.