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

Problem Exporting RadGrid to CSV/Pipe Delimited

1 Answer 185 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 27 Jan 2014, 09:30 PM
If I export to Excel or PDF, it works fine.  If I export to CSV or Pipe Delimited, the file only contains the header.  I've been through what is available online and none of those solutions want to work.

Here is my Grid Code

<telerik:RadGrid ID="gvStaffExport" 
                    AllowPaging="false"
                    AllowSorting="false"
                    AutoGenerateColumns="false"
                    CellPadding="0"
                    CellSpacing="0"
                    Width="100%"
                    PageSize="99999"
                    ShowFooter="false" 
                    runat="server">
    <ExportSettings IgnorePaging="true" OpenInNewWindow="true" ExportOnlyData="false">
        <Pdf PageWidth="297mm" PageHeight="210mm" DefaultFontFamily="Arial Unicode MS" PageTopMargin=".5in" BorderStyle="Thin" BorderColor="#666666" AllowPrinting="true" />
        <Excel FileExtension="xls" />
        <Csv ColumnDelimiter="Comma" FileExtension="csv" EncloseDataWithQuotes="true" RowDelimiter="NewLine"/>
    </ExportSettings>
    <MasterTableView AllowMultiColumnSorting="false" TableLayout="Fixed" ShowFooter="false">
        <Columns>
<telerik:GridBoundColumn DataField="username"
HeaderText="<%$ Resources: Resource, Username %>" HeaderStyle-BorderWidth="0" ItemStyle-BorderWidth="0">
<HeaderStyle
Font-Size="Smaller"
/>

                <ItemStyle Font-Size="Smaller"
/>

            </telerik:GridBoundColumn>

           
<telerik:GridBoundColumn DataField="userID"
Headertext="<%$ Resources: Admin_Common, strT_UserIdentifier %>" >

               
<HeaderStyle
Font-Size="Smaller"
/>

                <ItemStyle Font-Size="Smaller"
/>

            </telerik:GridBoundColumn>

           
<telerik:GridBoundColumn DataField="firstname"
HeaderText="<%$ Resources: Admin_Common, strT_FirstName %>" >

               
<HeaderStyle
Font-Size="Smaller"
/>

                <ItemStyle Font-Size="Smaller"
/>

            </telerik:GridBoundColumn>

           
<telerik:GridBoundColumn DataField="lastname"
HeaderText="<%$ Resources: Admin_Common, strT_LastName %>" >

               
<HeaderStyle
Font-Size="Smaller"
/>

                <ItemStyle Font-Size="Smaller"
/>

            </telerik:GridBoundColumn>

           
<telerik:GridBoundColumn DataField="Agency"
HeaderText="<%$ Resources: Admin_Common, strT_DefaultOffice %>" >

               
<HeaderStyle
Font-Size="Smaller"
/>

                <ItemStyle Font-Size="Smaller"
/>

            </telerik:GridBoundColumn>

           
<telerik:GridBoundColumn DataField="LastLogin"
HeaderText="<%$ Resources: strT_LastLogin %>"
>

               
<HeaderStyle
Font-Size="Smaller"
/>

                <ItemStyle Font-Size="Smaller"
/>

            </telerik:GridBoundColumn>

           
<telerik:GridTemplateColumn>

               
<ItemTemplate>

                   
<asp:Literal ID="litSelected"
runat="server"
/>

               
</ItemTemplate>

           
</telerik:GridTemplateColumn>

        </Columns>

    </MasterTableView>

</telerik:RadGrid>

 
Protected Sub gvStaffExport_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles gvStaffExport.NeedDataSource

        If IsPostBack AndAlso IsNumeric(Me.txtDaysSinceLastLoggedIn.Text) AndAlso Me.hidGridLoaded.Value = "0" Then
                Dim dtResults As New DataTable
                Dim StaffSearchDTOList As New List(Of StaffSearchDTO)
                Dim sLWIA As String = Me.ddlLWIA.SelectedValue.Trim
                If sLWIA = "0" Then sLWIA = ""
                Dim iDays As Integer = CInt(Me.txtDaysSinceLastLoggedIn.Text)
                StaffSearchDTOList = StaffSearchManager.GetListByLastLoginDate(iDays, sLWIA)
                dtResults = StaffSearchDTOList.ToDataTable
                gvStaffExport.DataSource = dtResults
                Me.hidGridLoaded.Value = "1"
                _IsGridLoaded = True
        End If

End Sub

Protected Sub btnExcelImage_Command(ByVal sender As Object, ByVal e As System.EventArgs)
       Export("E")
End Sub

Protected Sub lnkbExcel_Command(sender As Object, e As System.EventArgs)
        Export("E")
End Sub

Protected Sub btnCSVImage_Command(ByVal sender As Object, ByVal e As System.EventArgs)
       Export("C")
End Sub

Protected Sub lnkbCSV_Command(sender As Object, e As System.EventArgs)
        Export("C")
End Sub

Protected Sub btnPipeDelImage_Command(ByVal sender As Object, ByVal e As System.EventArgs)
      Export("I")
End Sub

Protected Sub lnkbPipeDel_Command(sender As Object, e As System.EventArgs)
        Export("I")
End Sub

Protected Sub lnkbPDF_Command(sender As Object, e As System.EventArgs)
       Export("P")
End Sub

Protected Sub btnPDFImage_Command(ByVal sender As Object, ByVal e As System.EventArgs)
       Export("P")
End Sub

Protected Sub Export(sType As String)

        gvStaffExport.ExportSettings.IgnorePaging = True
        gvStaffExport.ExportSettings.UseItemStyles = False
        gvStaffExport.ExportSettings.OpenInNewWindow = True

        Select Case sType
        Case "P"
               gvStaffExport.ExportSettings.UseItemStyles = True
               gvStaffExport.ExportSettings.Pdf.BorderType = GridPdfSettings.GridPdfBorderType.NoBorder
               gvStaffExport.ExportSettings.Pdf.ContentFilter = GridPdfFilter.NoFilter
               gvStaffExport.ExportSettings.Pdf.PageHeader.MiddleCell.TextAlign = GridPdfPageHeaderFooterCell.CellTextAlign.Left
               gvStaffExport.ExportSettings.Pdf.PageHeader.LeftCell.TextAlign = GridPdfPageHeaderFooterCell.CellTextAlign.Left
               gvStaffExport.ExportSettings.Pdf.FontType = Telerik.Web.Apoc.Render.Pdf.FontType.Embed
               gvStaffExport.MasterTableView.ExportToPdf()
        Case "C"
               gvStaffExport.ExportSettings.ExportOnlyData = False
               gvStaffExport.ExportSettings.Csv.ColumnDelimiter = GridCsvDelimiter.Comma
               gvStaffExport.MasterTableView.ExportToCSV()
        Case "E"
               gvStaffExport.ExportSettings.UseItemStyles = True
               gvStaffExport.MasterTableView.ExportToExcel()
         Case "I"
               gvStaffExport.ExportSettings.Csv.ColumnDelimiter = GridCsvDelimiter.VerticalBar
               gvStaffExport.ExportSettings.Csv.FileExtension = "txt"
               gvStaffExport.MasterTableView.ExportToCSV()
        End Select
End Sub


1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 30 Jan 2014, 04:30 PM
Hi Dan,

I have tested your code on a sample page and everything is working as expected on my end.

For your convenience I am attaching the page I have tested on my end. Please give it a try and see how it works on your side.

If you continue to face the issue, please elaborate on the version you are currently using, so we could try to replicate the issue on our end.


Regards,
Konstantin Dikov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Dan
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or