I get this error
blazor.server.js:1 [2022-01-14T07:52:44.127Z] Error: System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.Blazor.Grids.GridAggregate.OnInitializedAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
when trying to Sum Value
<SfGrid DataSource="@Patient" AllowPaging="true" AllowExcelExport="true" AllowFiltering="true">
<GridPageSettings PageCount="5" PageSizes="true"></GridPageSettings>
<GridColumns>
<GridColumn Field=@nameof(PatientReadDTO.Id) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120" Visible=false></GridColumn>
<GridColumn Field=@nameof(PatientReadDTO.Name) HeaderText="Patient Nam" Width="150"></GridColumn>
<GridColumn Field=@nameof(PatientReadDTO.DoctorName) HeaderText="Doctor Name" Width="150"></GridColumn>
<GridColumn Field=@nameof(PatientReadDTO.Opdtype) HeaderText="OPD Type"></GridColumn>
</GridColumns>
<GridAggregate>
<GridAggregateColumns>
<GridAggregateColumn Field="@nameof(PatientReadDTO.Opdfess)" Type="AggregateType.Sum" Format="C2">
<FooterTemplate>
@{ var SumValue = (context as AggregateTemplateContext);
<div>
Sum: @SumValue.Sum
</div>
}
</FooterTemplate>
</GridAggregateColumn>
</GridAggregateColumns>
</GridAggregate>
</SfGrid>
@Code{
private List<PatientReadDTO> Patient;
private Response<List<PatientReadDTO>> response = new Response<List<PatientReadDTO>> { Success = true };
protected override async Task OnInitializedAsync()
{
response = await pService.GetPatients();
if(response.Success)
{
Patient = response.Data.Take(5).ToList();;
}
}
}
I do this like from this demo https://blazor.syncfusion.com/demos/datagrid/aggregate?theme=bootstrap5
and 1 more issue i already define page value 5 or 10 from the grid but its show all the records at starting
Please review
|
<SfGrid DataSource="@Patient" AllowPaging="true" AllowExcelExport="true" AllowFiltering="true">
<GridColumns>
...
</GridColumns>
<GridAggregates>
<GridAggregate>
<GridAggregateColumns>
<GridAggregateColumn Field="@nameof(PatientReadDTO.Opdfess)" Type="AggregateType.Sum" Format="C2">
<FooterTemplate>
@{ var SumValue = (context as AggregateTemplateContext);
<div>
Sum: @SumValue.Sum
</div>
}
</FooterTemplate>
</GridAggregateColumn>
</GridAggregateColumns>
</GridAggregate>
</GridAggregates>
</SfGrid>
|
|
<GridPageSettings PageSize="5" PageSizes="true"></GridPageSettings>
|
Thankyou Sir
An Object is an instance of a Class , it is stored some where in memory. A reference is what is used to describe the pointer to the memory location where the Object resides. The message "object reference not set to an instance of an object" means that you are referring to an object the does not exist or was deleted or cleaned up. It's usually better to avoid a NullReferenceException than to handle it after it occurs. To prevent the error, objects that could be null should be tested for null before being used.
if (mClass != null)
{
// Go ahead and use mClass
mClass.property = ...
}
else
{
// Attempting to use mClass here will result in NullReferenceException
}
A NullReferenceException typically reflects developer error and is thrown in the following scenarios:
Hi Macronbell,
Thanks for the detailed explanation.
Regards,
Monisha