Datagrid CheckBox tied to Date Column

Hi All - new here and reading everything I can to learn...

I have a datagrid of things someone has to acknowledge - but the actual table has fields for date/time and user that acknowledged the row item. How can I tie a checkbox to that so that when checked, it writes a timestamp and userid, and in display, if those fields are null, show an empty check; if they're not null, show the box as checked and let me filter only checked items?

Hi @ToddB,

You can use the Template of the column to add a checkbox in it. You can then handle its Change event to set the timestamp and other properties.

Thank you - I'm trying to figure that out still... what about rendering the box as checked or unchecked based on if that date field is null or completed?

You can use the Value property of the CheckBox. If it is true the checkbox will be checked. Make sure to use an expression like this @(data.Timestamp != null)

I'm sorry - I'm new to this and just need some working examples to build off. I can't for the life of me figure out what the expression should look like. Normally the field would be ${data.AttachmentAcknowledged} but I can't figure out how to add the "!= null" in a way that doesn't cause build errors. I'm attempting to put this into the data-bind value. Could you tell me what the correct expression would be?

Thank you!

This will generate @bind-Value expression for two way binding while in your case you just need to set @(data.AttachmentAcknowledged != null). The generated code in this case will be:

<RadzenCheckBox Value="@(data.AttachmentAcknowledged != null)" ...

When I try that, I get errors:

dotnet: Pages\NewAttachments.razor(70,42): error CS0103: The name 'data' does not exist in the current context [C:\Dev\app\server\app.csproj]

dotnet: obj\Debug\netcoreapp3.1\Razor\Pages\NewAttachments.razor.g.cs(320,200): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type [C:\Dev\app\server\app.csproj]

dotnet:

dotnet: The build failed. Fix the build errors and run again.

dotnet: watch : Exited with error code 1

I might have gotten it - this worked:
@(appModelsDcReportsDbNewAttachment.AttachmentAcknowledged != null)

Does that seem right?

Next will be to bind some on-change events to write to two fields - a datetime and a userid

Yep, I've completely forgot that we rename the data context names due to conflicts with nested grids - the rename will not take place if you use plain Blazor expression with @ instead Radzen expression like ${}. What we can do in the next version is to check if the ${} expression is simple without any operators and only in this case we will generate @bind-Value=, in all other cases Value=.

1 Like

Perfect - glad I wasn't just completely off-base! I have one more question for the night I'll post separately. Thanks!

Could I ask for one more piece of help tonight? I posted my table in my other post. I have the checkbox displaying correctly in the datagrid but I'm struggling with the Change event. If the box gets "Checked" then I want to set the AcknowledgedBy of the current row to the current username; AND set the AttachmentAcknowledged to the current date/time. If it goes Unchecked then I want to clear those two fields. I'm going through all the examples I can find but I'm just not getting it.

Thanks again!

If you change your data in the page with the DataGrid nothing will submit to and update your database.