This is a migrated thread and some comments may be shown as answers.

Exporting GridView with columns created in code.

1 Answer 11 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alan
Top achievements
Rank 1
Alan asked on 02 Oct 2009, 09:59 AM

Hello,

I have a problem with exporting RadGridView using ToCsv() andToExcelML() methods.

While using AutoGenerateColumns property set to true everything works fine. 

However, when I'm trying to create columns in code in such a way:

  Telerik.Windows.Controls.GridViewDataColumn c1 = new Telerik.Windows.Controls.GridViewDataColumn();  
  c1.Header = "Name";  
  c1.CellTemplate = (DataTemplate)this.Resources["NameColumnTemplate"];  
  radGridView.Columns.Add(c1); 

with DataTemplate defined in XAML:

  <DataTemplate x:Key="NameColumnTemplate">  
  <TextBlock Text="{Binding Path=Name}"/>  
  </DataTemplate> 

In this case everything looks fine and RadGridView displays columns properly, but ToCsv() methods creates a string consist only of white spaces.

Is there any solution to this problem?

Regards

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 02 Oct 2009, 12:14 PM
Hi Alan,

You can set DataMemberBinding for the column to resolve this:
...
c1.DataMemberBinding = new Binding("Name");
...

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Alan
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or