Hi.
I am trying to export WebDataGrid Data using WebExcelExporter. I am using Infragistics 10.3.20103.2217.
I am able to download data for i am loosing the grid theme. How can i get the grid theme while downloading the gird data.
Here is my aspx page code
<asp:UpdatePanel ID="uwgCostCenterAdminUpdatePanel" runat="server"> <ContentTemplate> <ig:WebDataGrid ID="uwgCostCenterAdmin" runat="server" AutoGenerateColumns="false" Font-Size="Medium" DataKeyFields="CostCenter_id" Width="590px" OnInitializeRow="uwgCostCenterAdmin_InitializeRow" EnableAjax="true" AjaxIndicator-ImageUrl="../../images/Loading.gif" OnPageIndexChanged="uwgCostCenterAdmin_PageIndexChanged" OnColumnSorted="uwgCostCenterAdmin_ColumnSorted"> <Behaviors> <ig:Paging Enabled="true" PageSize="15" QuickPages="10" PagerMode="NumericFirstLast"> </ig:Paging> <ig:Sorting Enabled="true" SortingMode="Single" AscendingImageUrl="../../images/arrow_up.gif" DescendingImageUrl="../../images/arrow_down.gif"> <ColumnSettings> <ig:SortingColumnSetting ColumnKey="Configure" Sortable="false" /> </ColumnSettings> </ig:Sorting> </Behaviors> <Columns> <ig:BoundDataField Key="CostCenter_id" CssClass="hidden" DataFieldName="CostCenter_id"> <Header CssClass="hidden" /> </ig:BoundDataField> <ig:TemplateDataField Key="CostCenter" Width="20%"> <ItemTemplate> <asp:HyperLink ID="costcenterLink" runat="server" Text='<%# Eval("CostCenter") %>'></asp:HyperLink> </ItemTemplate> <Header Text="Cost Center" /> </ig:TemplateDataField> <ig:BoundDataField Key="Name" DataFieldName="CostCenter_Name" Width="30%"> <Header Text="Name" /> </ig:BoundDataField> <ig:BoundDataField Key="Description" DataFieldName="CostCenter_Desc" Width="35%"> <Header Text="Description" /> </ig:BoundDataField> <ig:TemplateDataField Key="Configure" Width="15%"> <ItemTemplate> <asp:HyperLink ID="costcenterConfigureLink" runat="server" Text="Configure"></asp:HyperLink> </ItemTemplate> <Header Text="Configure" /> </ig:TemplateDataField> </Columns> </ig:WebDataGrid> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="imgGo" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="cmbGroup" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel>
-- WebExcelExporter
<ig:WebExcelExporter ID="WebExcelExporter1" runat="server" DataExportMode="AllDataInDataSource" ExportMode="Download" OnCellExporting="WebExcelExporter1_CellExporting"> </ig:WebExcelExporter>
-- in Codebehind in Download Click event here is my code.
uwgCostCenterAdmin.Behaviors.Paging.Enabled = false; BindGrid(); uwgCostCenterAdmin.Columns[4].Hidden = true; WebExcelExporter1.DownloadName = "TEST"; this.WebExcelExporter1.Export(uwgCostCenterAdmin); uwgCostCenterAdmin.Behaviors.Paging.Enabled = true; BindGrid();
Please let me know what is wrong in my code. I need my grid theme to downloaded in my excel.
Thanks
Nagasai
Hi Nagasai,
What part of the theme are you losing exactly? All of it or a part here and there? Do you think you could attach a full working sample here?
regards,David Young
Hi
I am loosing formatting completely, Here is my scenario, Basically my project been upgraded form Infragistics NetAdvantage 2005 Volume 1 to 10.2.20102.1011 and later to 10.3.20103.2217.When i try to download using webexcelexporter i am loosing complete sytling.But when tried to use the same code in an new project i got styles for all the columns expect the one being modified with CellExporting Event.
Here is the code snippet,
protected void WebExcelExporter1_CellExporting(object sender, Infragistics.Web.UI.GridControls.ExcelCellExportingEventArgs e) { int currentColumnIndex = e.CurrentColumnIndex; int currentRowIndex = e.CurrentRowIndex; GridField field = this.uwgCostCenterAdmin.Columns[currentColumnIndex]; if (currentColumnIndex == 0 && !e.IsHeaderCell) { e.Cancel = true; string strText = this.uwgCostCenterAdmin.Rows[currentRowIndex - 1].Items[currentColumnIndex].Text; string formattedText = field.FormatValue(this.uwgCostCenterAdmin.Rows[currentRowIndex - 1].Items[currentColumnIndex].Value.ToString()); e.WorksheetCell.Value = strText; } }
I have attached sample code for reference. Please help me how can i get styles of the grid in my original project
Hi,
I have checked the source code and when you cancel ExcelCellExporting, we do nothing with that cell. So we do not set its value NOR apply the style. If you would like the style exported, I would suggest handling ExcelCellExported and simply set the cell value there. At that point, it would have gotten its styles.
regards,
David Young
Here is the sample code to remove Hyperlinks from Template field used in webdatagrid. You can do this in Cell Exporting event of webexcelexporter
protected void WebExcelExporter1_CellExporting(object sender, ExcelCellExportingEventArgs e) { if (!e.IsHeaderCell && !e.IsFooterCell && !e.IsSummaryCell) { int index = GetIndex(System.Convert.ToString(e.Worksheet.Rows[0].Cells[e.CurrentColumnIndex].Value)); GridRecordItem item = uwgCostCenterAdmin.Rows[e.CurrentRowIndex - 1].Items[index]; if (item.Column.GetType().Name == "TemplateDataField") { TemplateDataField field = item.Column as TemplateDataField; HyperLink costcenterLink = item.FindControl("costcenterLink") as HyperLink; if (costcenterLink != null) { e.WorksheetCell.Value = costcenterLink.Text; e.Cancel = true; } } else { e.WorksheetCell.Value = item.Text; e.Cancel = true; } } }
Yes, your correct but my intension was to clear the hyperlink which i am setting in my code for one column. How can i remove the hyperlink which i am setting in Initialize Row event, Here is my code what i did in Initialize row of weddatagird event
protected void uwgCostCenterAdmin_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e) { uwgCostCenterAdmin.Columns[0].Hidden = true; HyperLink configure = (HyperLink)e.Row.Items[4].FindControl("costcenterConfigureLink"); configure.NavigateUrl = "costCenterConfigure.aspx?CostCenterId=" + e.Row.Items[0].Text.ToString() + "&Name=" + Server.UrlEncode(e.Row.Items[2].Text.ToString()) + "&group_id=" + cmbGroup.SelectedValue.ToString() + "&company_id=" + cmbLocation.SelectedValue.ToString(); }
My intension was to remove these hyperlinks when exporting the grid data. How can i do that.
Thanks in advance.