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

GridTemplateColumn not working using Code

Thread ID:





128452 Jan 23,2017 11:42 PM UTC Feb 4,2017 06:54 AM UTC Xamarin.Forms 3
Tags: SfDataGrid
Vivek Agrawal
Asked On January 23, 2017 11:42 PM UTC

Hi Guys,

GridTemplateColumn not working using Code, but works if I use XAML.
I get lot of missing rows for some reason. Below is my code. my model is same as the sample you guys provide online.
Thanks for the Help!!

 grid = new SfDataGrid();
            var data = new OrderInfoRepository();
            grid.AutoGenerateColumns = false;
            var label1 = new Label()
                TextColor = Color.Black,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.Center
            var label2 = new Label(){
                TextColor = Color.Black,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.Center

            var cellGrid = new Grid(){
                ColumnDefinitions = {
                    new ColumnDefinition{Width = GridLength.Auto},
                    new ColumnDefinition{Width = GridLength.Auto}
            cellGrid.Children.Add(label2, 1, 0);
            label1.SetBinding(Label.TextProperty, "CustomerID");
            label2.SetBinding(Label.TextProperty, "ShipCountry");

            var template = new GridTemplateColumn(){HeaderText = "Custom", MappingName = "OrderID" , Width = 250};
            var dataTemplate = new DataTemplate(() =>
                return cellGrid;
            template.CellTemplate = dataTemplate;
            grid.ColumnSizer = ColumnSizer.Auto;
            grid.ItemsSource = data.OrderInfoCollection;
            Content = grid;

Attachment: TestSyncFusion_9a21f5af.zip

Divakar Subramaniam [Syncfusion]
Replied On January 24, 2017 10:10 AM UTC

Hi Vivek, 
Thanks for contacting Syncfusion Support. 
We have checked your query. We have resolved the query in sample level by creating new label inside a DataTemplate instead of creating outside of DataTemplate. Please refer the below code snippet. 
var dataTemplate = new DataTemplate(() => 
    var label1 = new Label() 
        TextColor = Color.Black, 
        HorizontalOptions = LayoutOptions.Center, 
        VerticalOptions = LayoutOptions.Center 
    label1.SetBinding(Label.TextProperty, "OrderID"); 
    return label1; 
We have attached the modified sample for your reference and you can download the same from the below link. 

K Guptha
Replied On February 4, 2017 12:53 AM UTC

Hi, in this example xaml code GridTemplareColumn is not working for me, it showing only OrderID, not displaying other binding values.

Attachment: TestSyncFusion954146049_426fecc.zip

Divakar Subramaniam [Syncfusion]
Replied On February 4, 2017 06:54 AM UTC

Hi Kumar, 
Thanks for the update. 
In the previous sample, we have added only one label and bound OrderID property to that label. That’s why only the OrderID values were displayed in SfDataGrid. Now, we have modified the sample based on your requirement and you can download the sample from the below link. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

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

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