hi everyone, so here I'm trying to export a WebDataGrid, but when I click on the export, the excel is empty and only the column name are appeared, here is my code:
Imports Infragistics.Web.UI.GridControls Public Class atte Inherits System.Web.UI.Page Protected Sub Generate_btn_Click(sender As Object, e As EventArgs) Handles Generate_btn.Click Dim ds As New DataSet3 Dim dt As DataTable = ds.DataTable1 For i As Integer = 1 To 10 dt.Rows.Add(i) Next WebDataGrid1.DataSource = dt WebDataGrid1.DataBind() End Sub Private Sub WebDataGrid1_InitializeRow(sender As Object, e As RowEventArgs) Handles WebDataGrid1.InitializeRow e.Row.Items.FindItemByKey("Type").CssClass = "TestCss" End Sub Protected Sub Export_btn_Click(sender As Object, e As EventArgs) Handles Export_btn.Click WebExcelExporter1.Export(WebDataGrid1) End Sub End Class
so I did a workaround and added the generate code before the export function, exported the data successfully but without any style.
Protected Sub Export_btn_Click(sender As Object, e As EventArgs) Handles Export_btn.Click Dim ds As New DataSet3 Dim dt As DataTable = ds.DataTable1 For i As Integer = 1 To 10 dt.Rows.Add(i) Next WebDataGrid1.DataSource = dt WebDataGrid1.DataBind() WebExcelExporter1.Export(WebDataGrid1) End Sub
any help for both issues?
thanks
Hello,
Thank you for contacting us!
I've created a sample based on your configuration and the styles are exported as expected, please do have a look. As you shared only your code behind, I am unable to determine whether the Initialize_rows is handled appropriately. Could you please make sure that it is bound on page_load, or though the Grid markup.
In order to run the sample, please make sure that there is a styleset file in the ig_res folder.
Looking forward to your reply.
WDGStylesExport.zip
thank you for your support,
first of all, I've followed your instructions, but still the same issue, exported without the data and without style, and also I didn't find the Styleset file in the ig_res folder! how I can get it?
and here is my code behind and the asp.net markup
Imports Infragistics.Web.UI.GridControls Public Class atte Inherits System.Web.UI.Page Protected Sub Generate_btn_Click(sender As Object, e As EventArgs) Handles Generate_btn.Click WebDataGrid1.DataSource = populate() End Sub Private Sub WebDataGrid1_InitializeRow(sender As Object, e As RowEventArgs) Handles WebDataGrid1.InitializeRow e.Row.Items.FindItemByKey("Name").CssClass = "TestCss" End Sub Protected Function populate() As DataTable Dim dt As DataTable = New DataTable() dt.Columns.Add("Name") Dim row As DataRow For i As Integer = 0 To 10 - 1 row = dt.NewRow() row.SetField(Of String)("Name", "Name" & i) dt.Rows.Add(row) Next Return dt End Function Protected Sub Export_btn_Click(sender As Object, e As EventArgs) Handles Export_btn.Click WebExcelExporter1.Export(WebDataGrid1) End Sub End Class
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="atte.aspx.vb" Inherits="HR_System.atte" %> <%@ Register assembly="Infragistics45.Web.v18.2, Version=18.2.20182.305, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.Web.UI.GridControls" tagprefix="ig" %> <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> <style type="text/css"> .TestCss{background-color: Red !important;} </style> <ig:WebExcelExporter ID="WebExcelExporter1" runat="server"> </ig:WebExcelExporter> <ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Width="100%" /> <asp:Button ID="Generate_btn" runat="server" Text="Generate" /> <asp:Button ID="Export_btn" runat="server" Text="Export" /> </asp:Content>
the result on the application
the exported data
Thanks for your reply.
The problem with exporting WebDataGrid is due to the fact that it has to be filled in Page_Load Sub not only with the interaction with the buttons. Therefore, as you can see in the attached sample below, we call the populate function in Page_Load, because in this way the grid will be exported correctly with its data.
As for the style problem, the solution is to place the styles in the Site.Master file so that the exporter has access to the required ones and they will be applied to the Excel worksheet.
1401.vbGridExport.zip
Please feel free to contact me if any additional questions regarding this matter arise.
find attached copy of my sample, the target file named atte.aspx,
exporting WebDataGrid.rar
let me know if you need the whole project in case I'm missing something.
As I see from the provided code and the sample above the export functionality should be working correctly.Could you provide a sample that reproduces this problem, so we could provide a better assistance based on the specifics.