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. (Last updated on: November 16, 2018).
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?

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.

XAML

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

XAML

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:

 

WPF

 

WRT

 

SilverLight

 

UWP

Article ID: Published Date: Last Revised Date: Platform: Control:
6077 01/22/2016 01/22/2016 UWP SfDataGrid
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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