|
<SfGrid DataSource="@OrderData">
<GridEditSettings AllowEditing="true" AllowAdding="true" AllowDeleting="true"></GridEditSettings>
<GridColumns>
@foreach (var prop in typeof(Order).GetProperties())
{
<GridColumn Field="@prop.Name" IsPrimaryKey="@(prop.Name == "OrderID")" AllowEditing="@prop.CanWrite">
<HeaderTemplate>
@{
//You can access the context here
var con = (context as Order);
}
@if (prop.Name == "OrderID")
{
<span>HeaderTemplate - ifcondition</span>
}
else
{
<span>HeaderTemplate - elsecondition</span>
}
</HeaderTemplate>
<Template>
@{
//You can access the context here
var con = (context as Order);
<span>@con.OrderID</span>
}
</Template>
</GridColumn>
}
</GridColumns>
</SfGrid> |
Hi Ville,
Greetings from Syncfusion support.
We have validated your query and based on your requirement we have prepared a sample for your reference.
In the sample we are able to use if-statement inside the header template and it is working as expected and also you can access the context as like in below code snippet.
<SfGrid DataSource="@OrderData"><GridEditSettings AllowEditing="true" AllowAdding="true" AllowDeleting="true"></GridEditSettings><GridColumns>@foreach (var prop in typeof(Order).GetProperties()){<GridColumn Field="@prop.Name" IsPrimaryKey="@(prop.Name == "OrderID")" AllowEditing="@prop.CanWrite"><HeaderTemplate>@{//You can access the context herevar con = (context as Order);}@if (prop.Name == "OrderID"){<span>HeaderTemplate - ifcondition</span>}else{<span>HeaderTemplate - elsecondition</span>}</HeaderTemplate><Template>@{//You can access the context herevar con = (context as Order);<span>@con.OrderID</span>}</Template></GridColumn>}</GridColumns></SfGrid>
Please get back to us if you have any other queries.
Regards,Jeevakanth SP.
|
<SfGrid DataSource="@OrderData">
<GridEditSettings AllowEditing="true" AllowAdding="true" AllowDeleting="true"></GridEditSettings>
<GridColumns>
@foreach (..)
{
@if (column.HeaderContentTemplate != null)
{
<GridColumn Field="..">
<HeaderTemplate>
<span>Header Template </span>
</HeaderTemplate>
</GridColumn>
}
else {
<GridColumn Field=".."></GridColumn>
}
}
</GridColumns>
</SfGrid> |