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

Export From RadGrid

9 Answers 236 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dony
Top achievements
Rank 1
dony asked on 02 Jan 2009, 12:51 PM
Hi,
I saw the demo code for exporting rad grid data in to csv files. But in my application I am not getting ExportToCSV() method. Can you tell me why I am not able to access this ExportToCSV() method. I am getting only ExportToExcel() and ExportToExcel2007(), even though i am getting ExportToExel as Obolete

9 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 05 Jan 2009, 08:01 AM
Hello dony,

Do you have latest version of Telerik.Web.UI?

Regards,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
dony
Top achievements
Rank 1
answered on 05 Jan 2009, 09:15 AM
yes i took the latest version. Now i am getting the exporttoCSV method also. But in the exported CSV file, no data are comming. Its just displaying columns like Template1, Template2...
0
Daniel
Telerik team
answered on 05 Jan 2009, 11:09 AM
Hello Dony,

You can use a Label control to export data from template columns:
<telerik:GridTemplateColumn UniqueName="Template1" HeaderText="Template1"
    <ItemTemplate> 
        <asp:Label ID="Label1" runat="server" Text='<%# Bind("CategoryName") %>'></asp:Label> 
    </ItemTemplate> 
</telerik:GridTemplateColumn> 

Kind regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
dony
Top achievements
Rank 1
answered on 05 Jan 2009, 03:04 PM
Hi Daniel,
Now in the csv File i am getting only the heading, content is not getting. But if i am exporting to excel, there i will get both heading and content.

But while opening the exported excel file it showing 1 popup message like, exported file is in a different format than the extension.
Because of this issue i am not able to use this file for import option. So please help me to resolve this issue.

Thanks and Regards,
Dony Jose Augustine

0
Daniel
Telerik team
answered on 05 Jan 2009, 04:43 PM
Hello Dony,

Regarding the export to CSV: Please make sure that ExportOnlyData is false in this case.

The file format error is mentioned in our documentation. I recommend you examine the following blog post:
"The file you are trying to open, '[filename]', is in a different format" Excel Error

Export to Microsoft Excel/Word/PDF/CSV

Please let us know if you need more information.

Kind regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
dony
Top achievements
Rank 1
answered on 06 Jan 2009, 04:30 AM
Hi Daniel,
This the code i am using..
C#
-------------------
    grdShoppingExport.ExportSettings.IgnorePaging = true;
            grdShoppingExport.ExportSettings.ExportOnlyData = false;
            grdShoppingExport.ExportSettings.FileName = "ShoppingExport";
            grdShoppingExport.MasterTableView.ExportToCSV();

ASPX
-----------------
<rad:RadGrid ID="grdShoppingExport" AllowSorting="false" BorderStyle="None" AutoGenerateColumns="false"
    AllowPaging="false" Skin="Desert" runat="server" GridLines="Vertical" Width="100%"
    EnableAJAX="true" RadControlsDir="~/App_Themes/RadControls/" OnDataBound="grdShoppingExport_DataBound">
    <MasterTableView Width="100%">
      <Columns>
        <rad:GridTemplateColumn Visible="false" HeaderText="" UniqueName="ID">
          <ItemTemplate>
            <asp:Label Visible="false" ID="lblProductId" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.ID") %>'></asp:Label>
          </ItemTemplate>
        </rad:GridTemplateColumn>
        <rad:GridTemplateColumn HeaderText="ModelNumber" UniqueName="ModelNumber">
          <ItemTemplate>
            <asp:Label ID="lblModelNumber" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.ModelNumber") %>'></asp:Label>
          </ItemTemplate>
        </rad:GridTemplateColumn>
        <rad:GridTemplateColumn HeaderText="Manufacturer" UniqueName="Manufacturer">
          <ItemTemplate>
            <asp:Label ID="lblManufacturer" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.Manufacturer") %>'></asp:Label>
          </ItemTemplate>
        </rad:GridTemplateColumn>
        <rad:GridTemplateColumn HeaderText="UPC" UniqueName="">
          <ItemTemplate>
          </ItemTemplate>
        </rad:GridTemplateColumn>
        <rad:GridTemplateColumn HeaderText="Name" UniqueName="Name">
          <ItemTemplate>
            <asp:Label ID="lblProductName" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.Name") %>'></asp:Label>
          </ItemTemplate>
        </rad:GridTemplateColumn>
        <rad:GridTemplateColumn HeaderText="Description" UniqueName="Description">
          <ItemTemplate>
            <asp:Label ID="lblDescription" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.Description") %>'></asp:Label>
          </ItemTemplate>
        </rad:GridTemplateColumn>
        <rad:GridTemplateColumn HeaderText="SellingPrice" UniqueName="SellingPrice">
          <ItemTemplate>
            <asp:Label ID="lblUnitCost" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.SellingPrice") %>'></asp:Label>
          </ItemTemplate>
        </rad:GridTemplateColumn>
        <rad:GridTemplateColumn HeaderText="ProductUrl" UniqueName="ProductUrl">
          <ItemTemplate>
            <asp:Label ID="lblProductUrl" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.ProductUrl") %>'></asp:Label>
          </ItemTemplate>
        </rad:GridTemplateColumn>
        <rad:GridTemplateColumn HeaderText="ImageUrl" UniqueName="ImageUrl">
          <ItemTemplate>
            <asp:Label ID="lblImageUrl" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.ImageUrl") %>'></asp:Label>
          </ItemTemplate>
        </rad:GridTemplateColumn>
        <rad:GridTemplateColumn HeaderText="shopping.com Categorization" UniqueName="">
          <ItemTemplate>
            <asp:Label ID="lblCategorisation" runat="server" Text="N/A"></asp:Label>
          </ItemTemplate>
        </rad:GridTemplateColumn>
        <rad:GridTemplateColumn HeaderText="Stock Availability" UniqueName="">
          <ItemTemplate>
            <asp:Label ID="lblAvailbility" runat="server" Text='Y'></asp:Label>
          </ItemTemplate>
        </rad:GridTemplateColumn>
        <rad:GridTemplateColumn HeaderText="Stock Description" UniqueName="">
          <ItemTemplate>
          </ItemTemplate>
        </rad:GridTemplateColumn>
        <rad:GridTemplateColumn HeaderText="Ground Shipping" UniqueName="">
          <ItemTemplate>
            <asp:Label ID="lblGrdShip" runat="server" Text="Yes"></asp:Label>
          </ItemTemplate>
        </rad:GridTemplateColumn>
        <rad:GridTemplateColumn HeaderText="Weight" UniqueName="Weight">
          <ItemTemplate>
            <asp:Label ID="lblWeight" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.Weight") %>'></asp:Label>
          </ItemTemplate>
        </rad:GridTemplateColumn>
        <rad:GridTemplateColumn HeaderText="Zip Code" UniqueName="Zip Code">
          <ItemTemplate>
            <asp:Label ID="lblZipCode" runat="server" Text='<%# ReturnZipCode()%>'></asp:Label>
          </ItemTemplate>
        </rad:GridTemplateColumn>
      </Columns>
    </MasterTableView>
  </rad:RadGrid>

----------------------------------------------------

Still this is exporting only the heading....
Please let me know what mistake i made in code?

Thanks and Regards,
Dony Jose Augustine



0
Daniel
Telerik team
answered on 09 Jan 2009, 09:38 AM
Hello Dony,

I noticed that you are using RadControls for ASP.NET suite and not RadControls for ASP.NET AJAX as I thought. Exporting data from template columns is not supported in the current version of the mentioned controls. We will add the missing functionality for the Q1 2009 release which is expected at the end of February.

Kind regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Kim
Top achievements
Rank 1
answered on 05 Jun 2009, 06:09 PM
We are using the new 2009 Q1 Controls.  I am trying to export to csv and I do not get any data only column headers. 

Here is what my .aspx columns look like:

 

<ItemStyle HorizontalAlign="Center" />

 

 

<HeaderStyle HorizontalAlign="Center" />

 

 

<ItemTemplate>

 

 

<table>

 

 

<tr>

 

 

<td>

 

 

<asp:Image ID="image1" runat="server" AlternateText="Billed" ImageUrl="~/App_Themes/Default/TelerikControls/Grid/billed.gif" />

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridTemplateColumn>

 

 

<HeaderTemplate>

 

 

<table>

 

 

<tr>

 

 

<td>

 

Mission No.

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td>

 

Mission Symbol

 

</td>

 

 

</tr>

 

 

</table>

 

 

</HeaderTemplate>

 

 

<ItemTemplate>

Here is my C# code:

 

 

//Exports Billing Errors Log to Excel

 

 

 

 

 

protected void exportExcelButton_Click(object sender, ImageClickEventArgs e)

 

{

billingErrorsRadGrid.ExportSettings.IgnorePaging =

true;

 

billingErrorsRadGrid.ExportSettings.OpenInNewWindow =

true;

 

billingErrorsRadGrid.ExportSettings.ExportOnlyData =

true;

 

billingErrorsRadGrid.ExportSettings.FileName =

"Billing Errors Log2";

 

billingErrorsRadGrid.MasterTableView.ExportToCSV();

}

 

Any ideas how we can get all of the data into the .csv file?

0
Daniel
Telerik team
answered on 11 Jun 2009, 10:41 AM
Hello Kim,

I'm afraid that the provided code is not enough to get a clear picture about your scenario.

Neither the Image nor the alternate text can't be exported to CSV. Also the tables won't be rendered in this file format since it is very simple and doesn't support such layouts.

It is possible to customize the exported data (or replace the whole output with your data):
    Protected Sub RadGrid1_GridExporting(ByVal source As ObjectByVal e As Telerik.Web.UI.GridExportingArgs) Handles RadGrid1.GridExporting 
        Dim output As New StringBuilder() 
        If (e.ExportType = ExportType.Csv) Then 
            For Each hrow In RadGrid1.MasterTableView.GetItems(GridItemType.Header) 
                '... build the output here 
            Next 
            For Each drow In RadGrid1.MasterTableView.Items 
                '... build the output here 
            Next 
            e.ExportOutput = output.ToString() 
        End If 
    End Sub 

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
dony
Top achievements
Rank 1
Answers by
Vlad
Telerik team
dony
Top achievements
Rank 1
Daniel
Telerik team
Kim
Top achievements
Rank 1
Share this question
or