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

Export to CSV not working

3 Answers 413 Views
Grid
This is a migrated thread and some comments may be shown as answers.
hitonline
Top achievements
Rank 1
hitonline asked on 21 Jun 2012, 09:30 PM
I have been trying to export my radgrid into CSV format, but somehow it'snot working even after following settings.
 <CommandItemSettings ShowExportToExcelButton="true" ShowExportToCsvButton="true"
            ShowAddNewRecordButton="false" ShowRefreshButton="false" />

It does not even hit  OnGridExporting="radInvoiceDetails_GridExporting" method.


3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Jun 2012, 05:36 AM
Hi,

I tried with the scenario and it is working fine at my end.If you are Ajaxifying the RadGrid ,the exporting feature of the control work with regular postbacks only. To bypass the limitation you can wire the OnRequestStart event of the ajax panel or ajax manager, determine whether the target control is ajaxified and explicitly disable its ajax mode to export with regular postback.

ASPX:
<telerik:RadAjaxManager ClientEvents-OnRequestStart="onRequestStart" ID="ajax" runat="server">        
 <AjaxSettings>
    <telerik:AjaxSetting AjaxControlID="RadGrid1">
        <UpdatedControls>
            <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
        </UpdatedControls>
    </telerik:AjaxSetting>
 </AjaxSettings>       
</telerik:RadAjaxManager>

Javascript:
<script type="text/javascript">  
    function onRequestStart(sender, args)
    {
        if (args.get_eventTarget().indexOf("ExportToCsvButton") >= 0) {
            args.set_enableAjax(false);
        }
    }
</script>

Please take a look into this help documentation.Provide the code if it doesn't help.

Thanks,
Shinu.
0
hitonline
Top achievements
Rank 1
answered on 22 Jun 2012, 03:23 PM
I am getting this extra button and image in exported report. (See the attachment)  looks like a command item which has been disabled in code

telerik:RadGrid ID="radInvoiceDetails" runat="server" Skin="WebBlue" AllowSorting="true"
    OnGridExporting="radInvoiceDetails_GridExporting" OnPreRender="radInvoiceDetails_PreRender"
    ExportSettings-HideStructureColumns="true" ExportSettings-ExportOnlyData="true"
    EnableLinqExpressions="false" Width="100%" AutoGenerateColumns="False" Height="100%"
    OnItemDataBound="radInvoiceDetails_ItemDataBound" PageSize="10" AllowPaging="True"
    EnableAJAX="True
protected void radInvoiceDetails_GridExporting(object sender, GridExportingArgs e)
        {
            if (e.ExportType == ExportType.Excel)
            {
                string fileName = radInvoiceDetails.ExportSettings.FileName + "." + radInvoiceDetails.ExportSettings.Excel.FileExtension;
                Response.ClearHeaders();
                Response.ContentType = "application/vnd.ms-excel";
 
                Response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
                 
                Response.Write(e.ExportOutput);
            }
        }
" RetrieveAllDataFields="true" OnNeedDataSource="radInvoiceDetails_NeedDataSource">
0
Shinu
Top achievements
Rank 2
answered on 25 Jun 2012, 07:01 AM
HI,

Try setting ExportOnlyData as true.
C#:
RadGrid1.ExportSettings.ExportOnlyData = true;
RadGrid1.MasterTableView.ExportToExcel();

Thanks,
Shinu.
Tags
Grid
Asked by
hitonline
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
hitonline
Top achievements
Rank 1
Share this question
or