How to set datetime empty in data grid - followup

On Jan 27 this question was answered as

[enchev]
If the database field is nullable the cell will be empty for null values.

I have a table is sql server with null dates.

image

This does work if you don't add a column specific format to the field.
image

But, in anticipation that the date may be filled, I added this simple format.

@String.Format("{0:d}", data.LTID3EffectiveDate)

It seems that when you add a template format, it no longer shows up as blank if the column is null. What code can be added to leave the field blank when null, and use the format when populated in the database?

thank you

You need to check if the value of the property is null and simply return null instead applying format.

and that can be done within the "Template Context" on the razor page as it will be at the row level?

Yes, it can be done via the ternary operator:

${data.LTID3EffectiveDate == null ? "" : String.Format("{0:d}", data.LTID3EffectiveDate)}

Sorry , new at this. Still not working. I also had to add the @ in front of data and String so they resolved to actual dates. Can a datetime even be checked for null using "=="?

${@data.LTID1EffectiveDate == null ? "" : @String.Format("{0:d}", data.LTID1EffectiveDate)}
        <RadzenDataGridColumn TItem="Fdid" Property="" Title="LTID2EffectiveDate" Sortable="true" Filterable="true">
            <Template Context="data">
                ${@data.LTID2EffectiveDate == null ? "" : @String.Format("{0:d}", data.LTID2EffectiveDate)}
            </Template>
        </RadzenDataGridColumn>

        <RadzenDataGridColumn TItem="Fdid" Property="LTID3EffectiveDate" Title="LTID3EffectiveDate" Sortable="true" Filterable="true">
            <Template Context="data">
                ${@data.LTID3EffectiveDate == null ? "" : @String.Format("{0:d}", data.LTID3EffectiveDate)}
            </Template>
        </RadzenDataGridColumn>

There are plenty of ways to check for null in C#:

${} expression is Radzen related that will be translated to plain Blazor expression @() on run.

Are you even using the Radzen IDE? You don't seem to although the thread topic is set so. My answer was Radzen specific. You probably need

@(data.LTID3EffectiveDate == null ? "" : String.Format("{0:d}", data.LTID3EffectiveDate))

You cannot check if a property of type DateTime is null as it is a struct (non-nullable). You can however check DateTime? which can be null. You didn't specify what property type you are actually using. It seems your date isn't null at all but 1/1/1900 so a different check should be used (unrelated to Radzen).