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.
Unfortunately, activation email could not send to your email. Please try again.

Grid export to excel no record to display

Thread ID:

Created:

Updated:

Platform:

Replies:

120716 Oct 7,2015 01:59 PM Oct 12,2015 12:30 AM ASP.NET Web Forms 4
loading
Tags: Grid
rapops
Asked On October 7, 2015 01:59 PM

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

Sellappandi Ramu [Syncfusion]
Replied On October 8, 2015 05:42 AM

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

rapops
Replied On October 9, 2015 04:03 PM

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

Sellappandi Ramu [Syncfusion]
Replied On October 12, 2015 12:30 AM

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


Sellappandi Ramu [Syncfusion]
Replied On October 12, 2015 12:30 AM

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;