What I'm doing here is using code to determine if there are 300 rows in my dataset. If there are, then I want to create the new WebGrid object and use that for the Excel export. If there are not 300, then I use the grid that is visible on the page. I'm doing this for performance reasons because the users can have grids with hundres, and thousands of rows which take quite a while to render on the page. When there are 300 rows, the save dialog box never comes up. Please help!
<igtblexp:UltraWebGridExcelExporter ID="gridExport" runat="server" DownloadName="Results.XLS"></igtblexp:UltraWebGridExcelExporter>
protected void SaveExcel(UltraWebGrid grid){ UltraWebGrid ug = new UltraWebGrid(); if (Session["reportGrid"] != null) { if (((DataSet)Session["reportGrid"]).Tables[0].Rows.Count > 300) { ug.DataSource = (DataSet)Session["reportGrid"]; ug.DataBind(); gridExport.Export(ug); } } else { gridExport.Export(grid); }}
I think for that to work, the grid should be part of the page control tree (e.g. exist on the page) and have valid ID. Could you please try the following - add a dummy placeholder on the page, e.g.
<asp:placeholder runat="server" ID="Placeholder1" ... />
and then prior
to exporting the fake grid, add it to the control collection of the placeholder, for example:
UltraWebGrid ug = new UltraWebGrid();
ug.ID = "ExportToExcelGrid";
Placeholder1.Controls.Add(ug)
Also, a good idea would be to place a break point on the first line of the SaveExcel method - this may produce additional clues.
Thanks for the tip. I'll give this a try this evening. When stepping through the code, it seems as though it hits all of the lines as expected, the prompt to save the file simply never appears. Hopefully this will solve it though :)
Yes, the reason why I am writing this is that I recently have seen this work in a client project - the technique there was slightly different - the second fake grid used for exporting was hidden originally (Visible = False) and then shown again only for the exporting to Excel, so you can also try that.
Please, let us know how it goes.
Can someone give more details about this.
I have a similar situation, where it takes a long time to export a large grid.
I don't fully understand the above example, what is "this.gridResults"?
Thanks
Your first idea worked! Thanks so much!
protected void SaveExcel(UltraWebGrid grid) { UltraWebGrid ug = new UltraWebGrid(); if (Session["reportGrid"] != null) { if (((DataSet)Session["reportGrid"]).Tables[0].Rows.Count > 400) { phHiddenGrid.Controls.Add(ug); ug.DataSource = (DataSet)Session["reportGrid"]; ug.DataBind(); gridExport.Export(ug); this.gridResults.Visible = false; } } else { this.gridResults.Visible = true; gridExport.Export(grid); } }