Hi,
I am trying to export my grid to excel. I am using the following code:HTML
<igtbl:UltraWebGrid ID="mainGrid" runat="server" Width="100%" OnInitializeDataSource="mainGrid_InitializeDataSource"OnInitializeLayout="mainGrid_InitializeLayout" Height="100%"><Bands><igtbl:UltraGridBand><AddNewRow View="NotSet" Visible="No"></AddNewRow></igtbl:UltraGridBand></Bands><DisplayLayout Name="mainGrid" RowHeightDefault="20px" AllowColSizingDefault="Free" AllowSortingDefault="OnClient" HeaderClickActionDefault="SortMulti" RowSizingDefault="Free" SelectTypeRowDefault="Extended" ViewType="OutlookGroupBy"><FrameStyle Width="100%" Height="100%"></FrameStyle><FilterOptionsDefault AllowRowFiltering="OnClient" FilterUIType="FilterRow"></FilterOptionsDefault><ActivationObject BorderColor="" BorderWidth=""></ActivationObject></DisplayLayout></igtbl:UltraWebGrid><igtblexp:UltraWebGridExcelExporter ID="UltraWebGridExcelExporter1" runat="server" ExportMode="Download" DownloadName="test1.xls"></igtblexp:UltraWebGridExcelExporter><asp:Button runat="Server" ID="ExportToExcelButton" Text="Export to Excel" OnClick="ExportToExcel" />
CODE BEHINDI have tried different codes:
2)mainGrid.DataBind();UltraWebGridExcelExporter1.Export(mainGrid);No results with either code.Please help!
Regards,
Nicolas
Hello,
Sp, yes, this is a known problem - this is actually a generic problem for HTTP/AJAX - file downloads will not work if they are "ajaxified". Since Excel export is essentially by default a file download task, it will not work if used inside WARP / UpdatePanel.
There is a workaround for this problem though if you are using WARP, please take a look at this forum thread for implementation details:
http://forums.infragistics.com/forums/p/8863/34770.aspx#34770
For UpdatePanel the only thing I can suggest it to move the control initiating the postback outside of UpdatePanel so that it is not "ajaxified".
Well, I'm having a similar situation, but I am using AJAX in UpdatePanel. Everything is working fine, but when I do a Export(grdResults, oWorkbook), it brings back a blank Excel worksheet.
Is there a way to export the grdResults using the AJAX UpdatePanel at the current state (with all filters, sorting, column moves applied)?
Hello Nicolas,
This may explain the problem - the grid will need to be binded to data again in the Export button event handler, since after that postback the data populated from the menu event handler will be lost.
I think the easiest solution would be to store the DataSet with data in Cache or Session in the LoadGridmethod and then restore the state from Session/Cache in the event handler called for the Export button (or you can directly call LoadGrid() in the event handler of the export button).
No AJAX at all. I just dragged and dropped a webgrid, a button and an excelexporter. nothing else!!!
I have also an infragistics menu that loads the grid passing it a stored procedure like this:
protected void LoadGrid(string storedProcecure) { mainGrid.DataSource = null; SqlConnection connMG = new SqlConnection(ConfigurationManager.AppSettings["connString"]); try { SqlCommand comm = new SqlCommand(storedProcecure, connMG); comm.CommandType = CommandType.StoredProcedure;
DataSet dsMG = new DataSet(); SqlDataAdapter daMG = new SqlDataAdapter(comm); daMG.Fill(dsMG);
if (dsMG.Tables[0].Rows.Count > 0) { mainGrid.DataSource = dsMG.Tables[0]; mainGrid.DataBind(); //hide the id column mainGrid.DisplayLayout.Bands[0].Columns[0].Hidden = true; mainGrid.Rows[0].Selected = true; } } catch (Exception ex) { lblErrorMessage.Text = ex.Message; } }
Thanks for reporting the problem and for the detailed information. Looking at that, I really cannot see anything wrong and everything seems fine. Is the grid you have showing all the rows correctly in browser using the same binding?
In any case, I am aware of one problem with exporting when AJAX is used. Are you using AJAX in any way - e.g. asp:UpdatePane, ig:WebAsyncRefreshPanel, the built-in grid load on demand mode - any other mode? Grid export is essentially a file download operation - file downloads are not compatible with ajax updates, so this may be the root of the problem.
If this is the case, make sure that the control initiating the export is not ajaxified.
If this does not help, any additional information on yoursetup could provide additional clues.