Hallo,
I have a WHDG binded to a dataset. I need to export a single band level choosen by user, preserving grid formatting.
How can i do this?
Thanks
Hello maxanziuttiBasically you cant cancel the row exporting by using the following code
protected void WebExcelExporter1_RowExporting(object sender, Infragistics.Web.UI.GridControls.ExcelRowExportingEventArgs e) { ContainerGridRecord cgr = e.GridRow as ContainerGridRecord; if (cgr != null) { if (cgr.Level != 1) { e.Cancel = true; } } }
because the exporting is designed to be hierarchical and if you cancel the export of parent level all the tree of reccords which is hanging on the canceled reccord would not be exported. Currently your best option is to use the following code :
protected void Button1_Click(object sender, EventArgs e) { WebExcelExporter1.EnableStylesExport = true;
DataSet ds = WebHierarchicalDataGrid1.DataSource as DataSet; DataTable dt = ds.Tables[1]; WebDataGrid1.DataSource = dt; WebDataGrid1.DataBind(); WebExcelExporter1.Export(WebDataGrid1); //WebExcelExporter1.Export(WebHierarchicalDataGrid1); }Which is taking the whole dataset, getting the table which is supposed to be exported and exporting it via using a hidden webdatagrid like this:<ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Visible="False" Width="400px" />
I haven't e.GridRow property in my version (i'm using last service release of 2011.1).
However, with this solution (having an hidden grid insted of original grid) I lose column formatting e data formatting made on InitalizeRow, right?
Hello maxanziutti,
Thank you for your patience.
As there are changes which have occured in the Infragistic's Excel Engine (and respectively the excel exporter) since version 11.1, Nikifor's approach may need to be revised for Volume 11.1. We will research your queries and will keep you posted of any developments.
Hello,Please let me know if you have any further questions regarding this issue.
Hello,In 11.1 getting the reference to the current row is done manually. There you have to count the exported rows and synchronize the count with the datasource of the grid and do calculations manually. For example if you are exporting second child row of the second parent row this means that as current row index you are having 1 for the first parent row + the number of all the child rows belonging to the first parent row + 1 for the second parent row + 2 for the second child row. And this way you can get manually the reference to the current grid record. This is unnecessary because as I have pointed in my previous post you can not cancel the parent row exporting without canceling the child row exporting. Yes with this solution you are losing the data formatting. If you want to have specific dataformat strings like {0:D} like You can create manually the columns for this hidden grid and to apply this formatting to them and use autogenerated columns to be false.