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

Exporting GridViewDataColumn.CellTemplate

3 Answers 151 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hemanth
Top achievements
Rank 1
Hemanth asked on 13 Aug 2010, 01:34 PM
Hi Team,

I am trying to export Radgridview in to a CSV file and facing few issues. My RadGridView contains DataColumns which binds directly and also I am embedding CellTemplate to add new control in to my radgrid.

1. <

 

 

telerik:GridViewDataColumn Header="Postal Code" UniqueName="PostalCode" DataMemberBinding="{Binding Code}" IsReadOnly="True"/>

 

2. <

 

 

telerik:GridViewDataColumn Header="Payment" UniqueName="Payment" >

 

 

 

 

<telerik:GridViewDataColumn.CellTemplate>

 

 

 

 

<DataTemplate>

 

 

 

 

<TextBox Text="{Binding payment, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True, Converter={StaticResource DisplayConverter}}" BorderThickness="0" IsEnabled="{Binding Pay_ID, Converter={StaticResource IsReadOnlyConverter}, Mode=TwoWay}" />

 

 

 

 

</DataTemplate>

 

 

 

 

</telerik:GridViewDataColumn.CellTemplate>

 

 

 

 

</telerik:GridViewDataColumn>

 


Now when I export this grid I get all the data from the column with name PostalCode but for the column Payment i do not get any data. Not sure what is that I am doing incorrectly but please guide me.

Export_Click Method:

private

 

 

void Export_Click(object sender, RoutedEventArgs e)

 

{

 

 

string extension = "";

 

 

 

ExportFormat format = ExportFormat.Html;

 

 

 

string selectedItem = "Csv";

 

extension =

 

"csv";

 

format =

 

ExportFormat.Csv;

 

 

 

SaveFileDialog dialog = new SaveFileDialog();

 

dialog.DefaultExt = extension;

dialog.Filter =

 

String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, selectedItem);

 

dialog.FilterIndex = 1;

 

 

if (dialog.ShowDialog() == true)

 

{

 

 

using (Stream stream = dialog.OpenFile())

 

{

 

 

GridViewExportOptions exportOptions = new GridViewExportOptions();

 

exportOptions.Format = format;

exportOptions.ShowColumnFooters =

 

true;

 

exportOptions.ShowColumnHeaders =

 

true;

 

exportOptions.ShowGroupFooters =

 

true;

 

RadGridView.Export(stream, exportOptions);

}

}

}




Thanks,
Hemanth

3 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 13 Aug 2010, 01:43 PM
Hi Hemanth,

 The Payment column has no DataMemberBinding set, so the RadGridView does not know which value to extract. However, seeing as how you have a custom template, perhaps it would be better to handle the ElementExporting event and override the value for that column's cells to make the exported value look like your template. You can learn more about the ElementExporting event here,

Sincerely yours,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Hemanth
Top achievements
Rank 1
answered on 16 Aug 2010, 12:41 PM
I modified my column like this.

 

 

 

<telerik:GridViewDataColumn Header="Payment" UniqueName="Payment" DataMemberBinding="{Binding payment}">

 

 

 

 

<telerik:GridViewDataColumn.CellTemplate>

 

 

 

 

<DataTemplate>

 

 

 

 

<TextBox Text="{Binding payment, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True, Converter={StaticResource DisplayConverter}}" BorderThickness="0" IsEnabled="{Binding Category_ID, Converter={StaticResource IsReadOnlyConverter}, Mode=TwoWay}" />

 

 

 

 

</DataTemplate>

 

 

 

 

</telerik:GridViewDataColumn.CellTemplate>

 

 

 

 

</telerik:GridViewDataColumn>

I added DataMemberBinding option even in the parent "<telerik:GridViewDataColumn>" tag which helped me to export directly the data. Not sure if this is a correct solution and would result any performance slag.

Thanks,
Hemanth

 

0
Yavor Georgiev
Telerik team
answered on 16 Aug 2010, 12:54 PM
Hello Hemanth,

 This will not result in any performance lag.

Regards,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Hemanth
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Hemanth
Top achievements
Rank 1
Share this question
or