I bind a WebDataGrid during run time and when I export the grid (tried both DataInGridOnly and AllDataInDataSource) the resulting excel file only contains the headers of the grid but none of the actual data rows. Any ideas? View states are set to true for the grid and the excel exporters.
Thanks for your help!
You have to set the grid DataSource before exporting.
I set the datasource and databind. I can see all the data rows within the webdatagrid, just not in the export...
Ah that did the trick. Really appreciate your help!
But do you execute the data binding logic on each page load or only if it is NOT PostBack?
If so, you should assign the data source before exporting:
protected void btn_excelExport_Click(object sender, EventArgs e) {
SqlDataSource sDC = new SqlDataSource(connectionString, selQuery); WebDataGrid1.DataSource = sDC; string excelExportName = "IRT_ETL_Data_" + txt_AppID.Text; WebExcelExporter1.DownloadName = excelExportName; WebExcelExporter1.Export(WebDataGrid1); }
Sure,
SqlDataSource sDC = new SqlDataSource(connectionString, selQuery);WebDataGrid1.Visible = true;WebDataGrid1.DataSource = sDC;WebDataGrid1.DataBind();
protected void btn_excelExport_Click(object sender, EventArgs e) { string excelExportName = "IRT_ETL_Data_" + txt_AppID.Text; WebExcelExporter1.DownloadName = excelExportName; WebExcelExporter1.Export(WebDataGrid1); }
<ig:WebExcelExporter ID="WebExcelExporter1" runat="server" DataExportMode="AllDataInDataSource"> </ig:WebExcelExporter>
Can you paste your code-behind here?