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

Radgrid Excel export with Custom row on top of the sheet

5 Answers 379 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aditya Rana
Top achievements
Rank 1
Aditya Rana asked on 17 Dec 2009, 07:44 AM
Hi ALL,

I am using ASP.Net 3.5, C# with latest Telerik component.
I am stuck with a problem related to excel export of the radgrid.

I have 2 dropdowns DDL1 and DDL2 , user select values from these 2 dropdownlist , and based on the selected values from 2 dropdownlist , I am showing data in radgrid.

Now user can export the Grid data to excel , everything is working fine upto here.
Now my problem is that how I can show the selected values of dropdownlist on top of the exported excel sheet ?
==============
for example- 

Value 1 - "Selected value from DDL1"    Value 2- "Selected value from DDL2"
(I want to add this row on top of the exported excel sheet.)

Exported Grid data here

==================

Please point me to right direction how can I achive this functionality ??

Thank you ,
Aditya .

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 19 Dec 2009, 05:58 PM
Hello Aditya,

The easiest way to insert custom text at the top of the exported file is to use the GridExporting event to modify the HTML output:
protected void RadGrid1_GridExporting(object source, Telerik.Web.UI.GridExportingArgs e)
{
    string customHTML = "<table><tr><td>Something</td><td>Something else</td></tr><table>";
    e.ExportOutput = e.ExportOutput.Replace("<body>", String.Format("<body>{0}", customHTML));
}


Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Aditya Rana
Top achievements
Rank 1
answered on 21 Dec 2009, 03:51 AM
Hi Daniel

Thanks for the reply.
Let me chek it, I will reply again after checking this code.

Thanks again.
0
Safa Amini
Top achievements
Rank 1
answered on 07 Jul 2010, 09:29 AM
hi,
I have a similar problem. I need to change the content of some of the cells before exporting to Word. I use the following code before exporting and also in GridExporting event. But still the original data is exported:
Private Sub grdOrders_GridExporting(ByVal source As ObjectByVal e As Telerik.Web.UI.GridExportingArgs) Handles grdOrders.GridExporting 
 
        For Each oCol As GridColumn In grdOrders.MasterTableView.Columns 
            Select Case oCol.ColumnType 
                Case "GridBoundColumn" 
                    If oCol.Visible Then 
                        For Each oRow As GridItem In grdOrders.MasterTableView.Items 
 
                            Try 
                                Dim oCell = oRow.Cells(oCol.OrderIndex) 
                                Dim tt = "some text..." 
                                oCell.Text = tt 
 
                            Catch ex As Exception 
                                'Stop 
                            End Try 
 
                            'Stop 
 
                        Next 
                    End If 
 
            End Select 
             
        Next 
 
    End Sub 

obviously there will be some other criteria as to which cells to modify, which I have removed from code above. I think there must be a way to get the grid to reproduce the export Html string and pass it back to the event argument. Otherwise, the grid still exports the original data.

Please help,
Thanks,
safa
0
Daniel
Telerik team
answered on 07 Jul 2010, 10:51 AM
Hello Safa,

I recommend that you use ItemCreated or ItemDataBound as explained in the documentation:
Word/Excel export (HTML-based) (Using ItemCreated/ItemDataBound section)
Note that the GridExporting event fires too late to modify the RadGrid contents.

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
Safa Amini
Top achievements
Rank 1
answered on 12 Jul 2010, 07:23 AM
Hello Daniel
Sorry for the late reply.
Your instructions worked fine.
Thank you very much.

regards,
safa
Tags
Grid
Asked by
Aditya Rana
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Aditya Rana
Top achievements
Rank 1
Safa Amini
Top achievements
Rank 1
Share this question
or