The Syncfusion® native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
I have a Grid where the grid items have a GUID for the primary key. When I click on the Add command button, I want to automatically populate the Id column with a new Guid value so that if I later click on Delete to remove a given row, the Guid can be used to allow the delete to work on the selected row. Right now, with the Id field null, when I click on the Delete button, all rows are deleted form the grid.
Should I use an event that fires when I click on the Add button or is there a built in way to generate the key for a new record?
If I need to use an event, which event would work the best for this need?
if (args.RequestType == Syncfusion.Blazor.Grids.Action.Save)
{
if (args.Data.Id == Guid.Empty)
{
args.Data.Id = Guid.NewGuid();
}
}
}
This seems to work the way I want.
Marked as answer
RNRahul Narayanasamy Syncfusion Team June 25, 2020 02:48 PM UTC
Hi David,
Greetings from Syncfusion.
We are happy to hear that you have achieved your requirement by yourself
Please get back to us if you need further assistance.
Regards,
Rahul
JOJohnAugust 17, 2021 03:58 PM UTC
Hi David,
I stumbled across this post looking for a solution to the same problem, and I used your solution until I realized that it works just as well to initialize the Id field to a new Guid in the first place:
public class TierPrice
{
public Guid Id { get; set; } = Guid.NewGuid();
}
This way, every newly created TierPrice object will have a unique Id to begin with.
Regards,
John
Need More Help?
Get personalized assistance from our support team.