﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - WebGrid Enterprise - Export Custom Data Source</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Export-Custom-Data-Source/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>Export Custom Data Source</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Export-Custom-Data-Source/</link><pubDate>Fri, 21 Aug 2015 03:29:28 GMT</pubDate><dc:creator>yudi</dc:creator><category>WebGrid</category><category>export</category><category>Custom Data</category><description>&lt;p&gt;&lt;span style="color: #1f497d;"&gt;You can try to use the following steps in order to export custom data which is different from the data binded to WebGrid:&lt;/span&gt;&lt;/p&gt;&lt;ol style="color: #1f497d;"&gt;&lt;li&gt;Add an ASP.NET Button into the page.&lt;/li&gt;&lt;li&gt;In OnClick server-side event handler, rebind the custom data source.&lt;/li&gt;&lt;li&gt;Programmatically invoke the export grid feature.&lt;/li&gt;&lt;li&gt;Rebind the original data source.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;The snippet code below shows how.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;protected void Button1_Click(object sender, EventArgs e)
{
    // Step 2: rebind the custom data source
    dsNorthwind_ReadOnlyTableAdapters.ShippersTableAdapter daCustomDataSource = new dsNorthwind_ReadOnlyTableAdapters.ShippersTableAdapter();
    WebGrid1.DataSource = daCustomDataSource.GetData(); // set WebGrid's DataSource 
    WebGrid1.RetrieveStructure();
    WebGrid1.RebindDataSource();

    // Step 3: invoke the Export Grid feature
    WebGrid1.ExportGrid(SetDynInfo()); // export grid data

    // Step 4: rebind the original data source
    dsNorthwind_ReadOnlyTableAdapters.ProductsTableAdapter daOriginalDataSource = new dsNorthwind_ReadOnlyTableAdapters.ProductsTableAdapter();
    WebGrid1.DataSource = daOriginalDataSource.GetData(); // set WebGrid's DataSource 
    WebGrid1.RetrieveStructure();
    WebGrid1.RebindDataSource();
}

private DynARInfo SetDynInfo()
{
    // configure the DynARInfo object   
    // as the parameter for the ExportGrid() method

    // need to configure 4 things :   
    // dynInfo.ReportType   
    // dynInfo.ReportPath   
    // dynInfo.IISReportPath   
    // dynInfo.DynPageOrientation

    DynARInfo dynInfo = new DynARInfo("excel", Server.MapPath("~/TempReports/"), "WebGridToExcel");
    dynInfo.IISReportPath = "/TempReports/";
    dynInfo.DynPageOrientation = PageOrientation.Portrait;
    return dynInfo;
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;WebGrid will show Products table. When the button is clicked, Shippers table will be exported.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Hope this helps.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>Export Custom Data Source</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Export-Custom-Data-Source/</link><pubDate>Wed, 19 Aug 2015 14:06:22 GMT</pubDate><dc:creator>rockymain</dc:creator><category>WebGrid</category><category>export</category><category>Custom Data</category><description>&lt;p&gt;I want to export Custom Data through webgrid export functionality. Custom Data is different from the data which is binded to the webgrid. Please suggest.&lt;/p&gt;&lt;p&gt;Regards,&lt;/p&gt;&lt;p&gt;Rockymain&lt;/p&gt;</description></item></channel></rss>