We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to bind based on MappingName for GridColumn CellTemplate or EditTemplate?

Platform: WinRT |
Control: SfDataGrid

In SfDataGrid, you can load DataTemplates for columns using GridColumn.CellTemplate. The DataContext for the templates loaded inside Grid are the underlying business object corresponding to that row regardless of MappingName of the column. So it is not possible to bind the values based on the MappingName of the GridColumn for the CellTemplate or EditTemplate of GridColumn. So you have to define the template for each column, separately.

The following section describes how to bind the DataTemplate of the GridCell based on MappingName of the column.

You can achieve this requirement by setting GridColumn.SetCellBoundValue to True as in the following code snippet, so that the DataContext for the template is changed to DataContextHelper from underlying record of the row. DataContextHelper contains the following properties.

Value – Value of the property GridColumn.MappingName in the underlying record.

Record – Underlying record of the row where the cell is present.

So by this concept, you can use the same template for more than one column, as DataContextHelper returns the value from record based on MappingName of the column.

The following code demonstrates how to bind the Value in DataTemplate.


The following code demonstrates how to set the DataTemplate key for the CellTemplate in GridColumn.


The following screenshot demonstrates the data template binding based on MappingName of the column. So, you can use the same template for different columns of SfDataGrid.



Sample Links:









You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile