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

[Solved] Problems Exporting Multi Child Grid to Excel

4 Answers 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 2
John asked on 20 Jul 2009, 02:36 PM
I am trying to export a grid with a parent and 2 children to excel.  This is inside a SharePoint web part.  I have used your examples as a starting place.  Here is the relavent code, I think.

 

protected override void OnInit(EventArgs e)

 

{

 

base.OnInit(e);

 

Page.ClientScript.RegisterStartupScript(

typeof(ParentChildGrid), this.ID, "_spOriginalFormAction = document.forms[0].action;_spSuppressFormOnSubmitWrapper=true;", true);

 

 

if (this.Page.Form != null)

 

{

 

string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];

 

 

if (!string.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt == "return _spFormOnSubmitWrapper();")

 

{

 

this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";

 

}

}

 

ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);

 

 

if (scriptManager == null)

 

{

scriptManager =

new RadScriptManager();

 

 

this.Page.Form.Controls.AddAt(0, scriptManager);

 

}

}

 

 

protected override void OnLoad(EventArgs e)

 

{

 

if (!_error)

 

{

 

try

 

{

 

base.OnLoad(e);

 

 

this.EnsureChildControls();

 

 

base.OnLoad(e);

 

 

if (_ParentList != null)

 

{

 

if (_ParentList != "")

 

{

 

RadAjaxPanel panel = new RadAjaxPanel();

 

panel.ID =

"Panel1";

 

 

this.Controls.Add(panel);

 

oGrid =

new RadGrid();

 

DefineComplexGrid();

 

//DefineSimpleMasterDetail();

 

cmdExport.Click +=

new EventHandler(cmdExport_Click);

 

cmdExport.Text =

"Export";

 

 

panel.Controls.Add(oGrid);

 

RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(this.Page);

 

 

if (ajaxManager == null)

 

{

ajaxManager =

new RadAjaxManager();

 

ajaxManager.ID =

"RadAjaxManager1";

 

Controls.Add(ajaxManager);

 

this.Page.Items.Add(typeof(RadAjaxManager), ajaxManager);

 

}

ajaxManager.AjaxSettings.AddAjaxSetting(oGrid, panel);

 

this.Controls.Add(cmdExport);

 

}

}

}

 

catch (Exception ex)

 

{

HandleException(ex);

}

}

}

 

 

void cmdExport_Click(object sender, EventArgs e)

 

{

oGrid.ExportSettings.ExportOnlyData =

true;

 

oGrid.ExportSettings.IgnorePaging =

true;

 

 

foreach (GridItem item in oGrid.MasterTableView.Items)

 

item.Expanded =

true;

 

oGrid.MasterTableView.ExportToExcel();

}

 



Any help you can give would be a big help, I am behind on a deadline.

Thanks,

John

4 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 2
answered on 20 Jul 2009, 05:41 PM
I realize that I posted in another thread, but I have tried everything I can think of from the articles on the telerik web site and nothing I try and do puts the child list data into the excel file.

Thanks,

John
0
Sebastian
Telerik team
answered on 23 Jul 2009, 02:08 PM

Hello John,

I reviewed your code snippets and noticed that you ajaxify the grid instance both by RadAjaxManager and RadAjaxPanel. Note that this is not necessary and you can safely replace the ajax panel with asp Panel to wrap the grid inside it. RadAjaxManager generated ajax panels around the updated control on-the-fly and the result would be the same.

Furthermore, in case the export button (with id cmdExport) is ajaxified as well, you will need to cancel the ajax explicitly when pressed following the directions from this documentation article.

Kind regards,

Sebastian
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.
0
John
Top achievements
Rank 2
answered on 23 Jul 2009, 05:10 PM
Sebastian,
           Thanks for your help.  First let me ask a basic question, does the radgrid support exporting a parent-child view to Excel?  I just want to make sure that I am not going down a rabbit hole.

I have tried every thing I can find to disable Ajax from inside the Web Part code and cannot get the child tables to show up in the excel file.  here is the current code for the button.

I have looked through all the events that occur in the ajaxmanager and radgrid and can't find the request started code that is in the documentation.

Thanks,

John

 

void cmdExport_Click(object sender, EventArgs e)

 

{

 

try

 

{

 

panel.EnableAJAX =

false;

 

ajaxManager.EnableAJAX =

false;

 

oGrid.ExportSettings.ExportOnlyData =

true;

 

oGrid.ExportSettings.IgnorePaging =

true;

 

 

foreach (GridItem item in oGrid.MasterTableView.Items)

 

item.Expanded =

true;

 

oGrid.MasterTableView.ExportToExcel();

}

 

catch (Exception ex)

 

{

HandleException(ex);

}

}

0
Sebastian
Telerik team
answered on 24 Jul 2009, 07:46 AM
Hello John,

You need to disable the ajax on the client before the request is sent to the server (as explained in the documentation). Setting the EnableAJAX property on the server will not be sufficient as this is too late stage to cancel the ajax and perform plain postback.

To export the grid hierarchy to Excel, verify that you set the HierarchyDefaultExpanded property at each level of the hierarchy (master or child tables) to true before invoking the ExportToExcel method.

Regards,
Sebastian
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
John
Top achievements
Rank 2
Answers by
John
Top achievements
Rank 2
Sebastian
Telerik team
Share this question
or