We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Grid export to excel no record to display

Hi,

I'm trying to export to Excel a simple Grid which has a SqlDataSource (declared at design time) as datasource.
The export process seems to run but then the produced Excel file doesn't contain any rows. It only displays 'No Record to display' although header columns are displayed correctly.

I've verified that Syncfusion.EJ.Export, Syncfusion.XlsIO.Base are referenced correctly and invoked in the code behind.

My development environment
Syncfusion ASP.NET 13.2.0.39 used with VS 2013.5 community edition.

My code behind

protected void Page_Load(object sender, EventArgs e)
        {
            SqlDataSource1.Select(DataSourceSelectArguments.Empty);
            Grid1.DataSourceID = SqlDataSource1.ID;
            Grid1.DataBind();
        }

        protected void Grid1_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e)
        {
            ExcelExport xlXport = new ExcelExport();
            xlXport.Export(Grid1.Model, (IEnumerable)Grid1.DataSource, "xlXport.xlsx", ExcelVersion.Excel2013, true, true, ExportTheme.FlatLime);
        }

The Grid declaration in the aspx file:

<ej:Grid ID="Grid1" runat='server' AllowFiltering="true" AllowPaging="true" AllowGrouping="true"
        IsResponsive="true" OnServerExcelExporting="Grid1_ServerExcelExporting" >
        <FilterSettings ShowFilterBarStatus="true" FilterType="Menu" />
        <ToolbarSettings ShowToolbar="true" ToolbarItems="excelExport, pdfExport"></ToolbarSettings>
    </ej:Grid>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:XXXXConnectionString %>" SelectCommand="SELECT * FROM [TABLE]"></asp:SqlDataSource>


Thanks in advance

4 Replies

SR Sellappandi Ramu Syncfusion Team October 8, 2015 09:42 AM UTC

Hi Rapops,

Thanks for contacting Syncfusion support.

In the provided code, you are using Grid dataSource directly to Export() method, which is the cause for the issue. 

While setting data source to Grid using sqlDataSource element, the Grid dataSouce will be Null. So it will show the “No records to display” message. Give the list of data to export method and convert SQL data as list data, and use that data in Export() method.

Please refer to the following code example, sample,


protected void FlatGrid_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e)

        {

            ExcelExport exp = new ExcelExport();

            DataView data = (DataView)SqlData.Select(new DataSourceSelectArguments());

            IList data1 = data;

            DataTable dt = data.Table;

            var emp = (from DataRow row in dt.Rows


                   select new Order

                   {

                       OrderID = Convert.ToInt32(row["OrderID"]),

                       CustomerID = row["CustomerID"].ToString(),

                       Freight = Convert.ToDouble(row["Freight"]),

                       EmployeeID = Convert.ToInt32(row["EmployeeID"]),

                       ShipCountry = row["ShipCountry"].ToString()


                   }).ToList();

            exp.Export(FlatGrid.Model, (IEnumerable)emp, "Export.xlsx", ExcelVersion.Excel2010, true, true, "flat-lime");
        }


Sample: http://www.syncfusion.com/downloads/support/forum/120716/ze/Sample_120716-599975427

Regards,
Sellappandi R


RA rapops October 9, 2015 08:03 PM UTC

Hi Sellappandi,

Many thanks for your response.

I've rewritten my code as you suggested and it now works. All record exported to Excel.
The provided code sample was of great help!

Many thanks!!

Rapops


SR Sellappandi Ramu Syncfusion Team October 12, 2015 04:30 AM UTC

Hi Rapops, 

We are happy that the provided suggestion helped you. 

Please get back to us if you need any further assistance.  

Regards, 

Sellappandi R



SR Sellappandi Ramu Syncfusion Team October 12, 2015 04:30 AM UTC

Hi Rapops, 

We are happy that the provided suggestion helped you. 

Please get back to us if you need any further assistance.  

Regards, 

Sellappandi R


Loader.
Live Chat Icon For mobile
Up arrow icon