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

ExportToExcel and ItemDataBound

3 Answers 210 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jamey Johnston
Top achievements
Rank 1
Jamey Johnston asked on 16 Sep 2010, 08:34 PM
I have a RadGrid with ExportToExcel functionality.  This part is working correctly when simply displaying what's on the grid.  However I'm having two issues with expanding this functionality:

1) If I add a column to my grid that does not have a "DataField" property it does not get exported.  I can work around this by supplying this parameter, but it would be nice if I could just add a column to be exported.

2) When I change the data in the ItemDataBound event, the changes don't come through.  In other words, say the column contains the value 3, and in the ItemDataBound event I change it to 20 (see below for how I am doing that), in the Excel document I still see 3 as the output.  Note that the code does execute without errors, and also if I export to PDF the correct, updated data does come through, only Excel shows the "old" data.

 

protected void RadGridHardware_ItemDataBound(object sender, GridItemEventArgs e)

 

{

 

if (e.Item is GridDataItem)

 

{

 

GridDataItem dataItem = (GridDataItem)e.Item;

 

dataItem[

"Quantity"].Text = "20";

 

}

Any thoughts or ideas?

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 22 Sep 2010, 10:23 AM
Hello Jamey,

Judging by the available information, I suppose that you are using the ExcelML format.

1) when using this format RadGrid gets the data directly from the datasource - this is why it needs the DataField property.

2) due to the aforementioned reason, RadGrid will ignore the changes you made in the ItemDataBound handler. Here you can handle the ExcelMLRowCreated event and modify the data directly in the ExcelML structure.

Let me know if your scenario is different.

Best 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
Jamey Johnston
Top achievements
Rank 1
answered on 22 Sep 2010, 03:04 PM
That is what I went with so I'd at least have it working.  Just found it interesting that filters (from the grid) were still used even though it otherwise seemed to be "bypassing" the grid, and when exporting to PDF it does use the databound event of the grid.  I may see if I can figure out how to turn off ExcelML so I don't have to do a bunch of duplicate code work in databound and rowcreated.  Thanks!

Jamey
0
Daniel
Telerik team
answered on 22 Sep 2010, 03:33 PM
Hello Jamey,

You can set the desired Excel format via the ExportSettings Excel-Format property:

RadGrid export overview

<ExportSettings Excel-Format="ExcelML" />

<ExportSettings Excel-Format="Html" />

Best 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
Tags
Grid
Asked by
Jamey Johnston
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Jamey Johnston
Top achievements
Rank 1
Share this question
or