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 Nicolas,
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.
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; } }