Articles in this section
Category / Section

How to export the data when grid is in UpdatePanel

1 min read

When the grid is in Update Panel the partial post will be done and hence exporting will not work in grid.

Although we can achieve the Exporting using below two ways.

  1. By making the grid as Post Back control
  2. Saving the Exported file instead of downloading

 

  1. By making the grid as Post Back control.

We can change the post back grid as post back control by using PostBackTrigger in the Default.aspx page. Now the grid will send post back on its operation and hence the export will work as expected.

Example:

Grid rendering control:

ASP:

<asp:UpdatePanel runat="server">
<ContentTemplate>
     <ej:Grid ID="FlatGrid" runat="server" AllowSorting="True" OnServerWordExporting="FlatGrid_ServerWordExporting" OnServerPdfExporting="FlatGrid_ServerPdfExporting" OnServerExcelExporting="FlatGrid_ServerExcelExporting" AllowPaging="True">
            <ToolbarSettings ShowToolbar="true" ToolbarItems="excelExport,wordExport,pdfExport"></ToolbarSettings>
            <Columns>
                <ej:Column Field="OrderID" HeaderText="Order ID" />
                <ej:Column Field="CustomerID" HeaderText="Customer ID" />
                <ej:Column Field="EmployeeID" HeaderText="Employee ID" />
                <ej:Column Field="Freight" HeaderText="Freight" />
                <ej:Column Field="OrderDate" HeaderText="Order Date" Format="{0:MM/dd/yyyy}" />
                <ej:Column Field="ShipCity" HeaderText="Ship City" />
            </Columns>
        </ej:Grid>
</ContentTemplate>
 
<Triggers>
<asp:PostBackTrigger controlid="FlatGrid"/>
</Triggers>
</asp:UpdatePanel>
</asp:Content>
 

 

  1. Saving the Exported file instead of downloading

If we don’t want to use the grid as a post back control then we can save the exported file in the specified location instead of downloading.

We can set the “isLocalSave” property as true and also set the path for the property filePath of the Export method for saving the exported file in the specified file path.

Example:

Default.aspx.cs
 
protected void FlatGrid_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web .GridEventArgs e)
        {   
            ExcelExport exp = new ExcelExport();
            exp.Export(FlatGrid.Model, (IEnumerable)FlatGrid.DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-lime", true, @"../Download");
        }
 

 

Note: if the exported file exists already then the new file will be replaced in the same folder.

The above code example will work for both Word and PDF also.

 

Result:

                                            Figure: Exported file

 

 

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied