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

Csv export missing data in GridTemplateColumn

7 Answers 358 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alexandre BARBIER
Top achievements
Rank 1
Alexandre BARBIER asked on 25 Aug 2010, 01:04 PM
I'm trying to export my grid content into csv file.

All my grid is created by code into Page_Init method. Here is the code to setup export settings :
RadGrid1.ExportSettings.Csv.ColumnDelimiter = GridCsvDelimiter.Semicolon;
RadGrid1.ExportSettings.Csv.FileExtension = ".csv";
RadGrid1.ExportSettings.Csv.RowDelimiter = GridCsvDelimiter.NewLine;
RadGrid1.ExportSettings.FileName = "export";
RadGrid1.ExportSettings.IgnorePaging = true;
RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.ExportSettings.ExportOnlyData = true;

my grid contain 11 custom column where content is displayed by a custom item template.
When I use this method : RadGrid1.MasterTableView.ExportToCSV() I got a csv file containing only my first 2 columns wich are not custom column (just GridBoundColumn)
I saw here:http://www.telerik.com/community/forums/aspnet-ajax/grid/csv-exporting.aspx
that I need to do special code to get content from my custom template controls and assign it to the item Text property.
Here is my code :
void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExportToCsvCommandName)
    {
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        {
            var typeCompteurs = from tc in DbContext.TypeCompteurs
                        orderby tc.Ordre
                        select tc;
            foreach (var t in typeCompteurs)
            {
                Literal lt = item[t.LibelleTypeCompteur].FindControl("ctrlAcquis_" + t.LibelleTypeCompteur) as Literal;
                if (lt != null)
                    item[t.LibelleTypeCompteur].Text = lt.Text;
            }
        }
        RadGrid1.MasterTableView.ExportToCSV();
    }
}

But I've the same issue. The csv file contains the columns but with no values :(

Any idea    ?

Thanks

7 Answers, 1 is accepted

Sort by
0
Alexandre BARBIER
Top achievements
Rank 1
answered on 30 Aug 2010, 07:55 AM
Please help ! ... :)
0
Daniel
Telerik team
answered on 30 Aug 2010, 03:41 PM
Hello Alexandre,

First, I recommend that you set ExportOnlyData="false" when exporting GridTemplateColumns to CSV. Second, you can replace the Literal controls with Labels since RadGrid strips the Literals by default.

I hope this helps.

Kind regards,
Daniel
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
Alexandre BARBIER
Top achievements
Rank 1
answered on 30 Aug 2010, 04:38 PM
Thanks for answer.
I've replaced all the literals by labels.
Set exportOnlyData to false

unfortunately I got a JS error and no csv file :( :
Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; InfoPath.3; .NET CLR 3.5.30729; .NET CLR 3.0.30729; MS-RTC LM 8; .NET4.0C; .NET4.0E)
Timestamp: Mon, 30 Aug 2010 15:34:51 UTC


Message: 'this.ColGroup.Cols' is null or not an object
Line: 3838
Char: 1
Code: 0
URI: http://serverurl/Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=ctl00_PlaceHolderMain_boconges_radscript_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bTelerik.Web.UI%2c+Version%3d2010.1.519.35%2c+Culture%3dneutral%2c+PublicKeyToken%3d121fae78165ba3d4%3afr-FR%3afcd44c12-f50d-4937-b05d-1aa46b5c5b3e%3a24ee1bba%3a1e771326%3a2bef5fcc%3a58366029%3aaa288e2d


It seems that Export is not supported in ajaxified grid. (http://www.telerik.com/help/aspnet-ajax/grdexportwithajax.html)
I will try the workaround ....
0
Alexandre BARBIER
Top achievements
Rank 1
answered on 30 Aug 2010, 04:49 PM
So, I disabled the ajax when exporting to csv.
I got the csv file

But the problem is already here :-(
0
Daniel
Telerik team
answered on 02 Sep 2010, 01:49 PM
Hello Alexandre,

Can you please post the modified code in this thread? This way I will be able to find the problem and then provide more to-the-point answer. Alternatively you can attach the files to a regular support ticket.

Regards,
Daniel
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
Alexandre BARBIER
Top achievements
Rank 1
answered on 03 Sep 2010, 12:12 PM
Hello

I cannot attach the full project source because too many components are involved to allow the page to run.
So I've started a new sample project that use the same approach...

But Actually I can not reproduce the problem. The CSV export work like a charm in my sample ! 

Only when I set RadGrid1.ExportSettings.ExportOnlyData to true, I can reproduce this issue on my sample project. But in my "real" project I set this property to false but it's change nothing :(

I will try to find the difference between my real project and the sample project and if I can reproduce the issue, I will post the code to the forum !

Thanks !
Regards.
0
Irving
Top achievements
Rank 2
answered on 14 Mar 2016, 03:20 AM
[quote]Daniel said:Hello Alexandre,

First, I recommend that you set ExportOnlyData="false" when exporting GridTemplateColumns to CSV. Second, you can replace the Literal controls with Labels since RadGrid strips the Literals by default.

I hope this helps.

Kind regards,
Daniel
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
 

[/quote]

 

This totally helps me with the problem i'm facing thanks !!

Tags
Grid
Asked by
Alexandre BARBIER
Top achievements
Rank 1
Answers by
Alexandre BARBIER
Top achievements
Rank 1
Daniel
Telerik team
Irving
Top achievements
Rank 2
Share this question
or