Exporting Grid Into PDF / Excel / Html etc.

Oct 9, 2016 at 11:04 AM
HI,

Ive been using this Grid.Mvc, and was anxious about having an export option. I found lots of discussions here, but i didn't find the generic solution. I have implemented an export option in this Grid. Just in case if anyone is interested, they add this code to get the export option.

For Export i've used the below nuget package:
https://www.nuget.org/packages/Exporter/
(This package helps to export in PDF/ Excel /Html etc.)
We just have to install this package in the GridMvc Project only, not in the .Site

Export Folder
First I Created and Export Folder in the GridMvc solution.
And then i created 3 files with the below code:

ExportGridItemsProcessor.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.Serialization;
using System.Web;
using System.Web.UI.WebControls;
using DocumentFormat.OpenXml.Office2010.ExcelAc;
using ExporterObjects;


namespace GridMvc.Exporting
{
    /// <summary>
    ///     Grid items filter proprocessor
    /// </summary>
    internal class ExportGridItemsProcessor<T> : IGridItemsProcessor<T> where T : class
    {
        private readonly IGrid _grid;
        private IGridExportSettings _settings;
        public string DownloadUrl = "";

        public ExportGridItemsProcessor(IGrid grid, IGridExportSettings settings)
        {
            if (settings == null)
                throw new ArgumentNullException("settings");
            _grid = grid;
            _settings = settings;
        }

        public void UpdateSettings(IGridExportSettings settings)
        {
            if (settings == null)
                throw new ArgumentNullException("settings");
            _settings = settings;
        }

        #region IGridItemsProcessor<T> Members

        public IQueryable<T> Process(IQueryable<T> items)
        {
            string exportTo = _settings.ExportTo;

            ExportToFormat exportType = ExportToFormat.PDFtextSharpXML;

            switch (exportTo.ToLower())
            {
                case "pdf":
                {
                    exportType = ExportToFormat.PDFtextSharpXML;
                    break;
                }
                case "excel":
                {
                    exportType = ExportToFormat.Excel2007;
                    break;
                }

            }

            var exp = new ExportList<T>();
            exp.PathTemplateFolder = HttpContext.Current.Server.MapPath("~/content/module/templates");
            DownloadUrl = "~/content/module/exports/document" + ExportBase.GetFileExtension(exportType);
            var filePathExport = HttpContext.Current.Server.MapPath(DownloadUrl);
            exp.ExportTo(items, exportType, filePathExport);
            return Enumerable.Empty<T>().AsQueryable(); //Clear Items
        }

        #endregion
    }
}
IGridExportSettings.cs

namespace GridMvc.Exporting
{
    public interface IGridExportSettings
    {
        /// <summary>
        ///     Export type
        /// </summary>
        string ExportTo { get; set; }
        
    }
}
QueryStringExportSettings.cs

using System;
using System.Web;

namespace GridMvc.Exporting
{
    /// <summary>
    ///     Grid export settings takes from query string
    /// </summary>
    public class QueryStringExportSettings : IGridExportSettings
    {
        public const string DefaultExportQueryParameter = "export-to";
        public readonly HttpContext Context;
        private string _exportQueryParameterName;
        

        public QueryStringExportSettings()
            : this(HttpContext.Current)
        {
        }

        public QueryStringExportSettings(HttpContext context)
        {
            if (context == null)
                throw new ArgumentException("No http context here!");
            Context = context;
            ExportQueryParameterName = DefaultExportQueryParameter;
            
        }

        public string ExportQueryParameterName
        {
            get { return _exportQueryParameterName; }
            set
            {
                _exportQueryParameterName = value;
                RefreshColumn();
            }
        }


        #region IGridExportSettings Members

        public string ExportTo { get; set; }

        #endregion

        private void RefreshColumn()
        {
            string currentExportTo = Context.Request.QueryString[ExportQueryParameterName] ?? string.Empty;
            ExportTo = currentExportTo;
        }
       
        
    }
}
After that i modifed

Grid.cs file with the following changes

.......
.......
private readonly IGridAnnotaionsProvider _annotaions;
        private readonly IColumnBuilder<T> _columnBuilder;
        private readonly GridColumnCollection<T> _columnsCollection;
        private readonly FilterGridItemsProcessor<T> _currentFilterItemsProcessor;
        private readonly SortGridItemsProcessor<T> _currentSortItemsProcessor;
        private readonly ExportGridItemsProcessor<T> _currentExportItemsProcessor; //Added

        private int _displayingItemsCount = -1; // count of displaying items (if using pagination)
        private bool _enablePaging;
        private IGridPager _pager;

        private IGridItemsProcessor<T> _pagerProcessor;
        private IGridSettingsProvider _settings;

        public Grid(IEnumerable<T> items)
            : this(items.AsQueryable())
        {
        }

        public Grid(IQueryable<T> items)
            : base(items)
        {
            #region init default properties

            //set up sort settings:
            _settings = new QueryStringGridSettingsProvider();
            Sanitizer = new Sanitizer();
            EmptyGridText = Strings.DefaultGridEmptyText;
            Language = Strings.Lang;

            _currentSortItemsProcessor = new SortGridItemsProcessor<T>(this, _settings.SortSettings);
            _currentFilterItemsProcessor = new FilterGridItemsProcessor<T>(this, _settings.FilterSettings);
            currentExportItemsProcessor = new ExportGridItemsProcessor<T>(this, _settings.ExportSettings); //Added

            AddItemsPreProcessor(_currentFilterItemsProcessor);
            if(_settings.ExportSettings.ExportTo.Length>0) AddItemsPreProcessor(_currentExportItemsProcessor);
            InsertItemsProcessor(0, _currentSortItemsProcessor);

            _annotaions = new GridAnnotaionsProvider();

            #endregion

            //Set up column collection:
            _columnBuilder = new DefaultColumnBuilder<T>(this, _annotaions);
            _columnsCollection = new GridColumnCollection<T>(_columnBuilder, _settings.SortSettings);
            RenderOptions = new GridRenderOptions();

            ApplyGridSettings();

            
        }
......
......
.......
And This is how my GridBase.cs looks like
....
....
 //pre-processors process items before adds to main collection (like filtering)
        private readonly List<IGridItemsProcessor<T>> _preprocessors = new List<IGridItemsProcessor<T>>();
        private readonly List<IGridItemsProcessor<T>> _processors = new List<IGridItemsProcessor<T>>();
        protected IEnumerable<T> AfterItems; //items after processors
        protected IQueryable<T> BeforeItems; //items before processors

       
        private int _itemsCount = -1; // total items count on collection
        private bool _itemsPreProcessed; //is preprocessors launched?
        private bool _itemsProcessed; //is processors launched?

        private bool _isExport = false; // default export is false
        private string _exportUrl = string.Empty; //export url for downloading

......
.......

AT THE END OF GRIDBASE.CS CLASS ADD BELOW

/// <summary>
        /// Export Options For View 
        /// </summary>
        public bool IsExport
        {
            get
            {
                foreach (var gridItemsProcessor in _preprocessors)
                {
                    if (gridItemsProcessor.GetType() == typeof (ExportGridItemsProcessor<T>))
                    {
                        _isExport = true;
                        return _isExport;
                    }
                }
                
                
                return _isExport;
            }
            set
            {
                _isExport = value;
            }
        }

        public string ExportUrl
        {
            get
            {
                foreach (var gridItemsProcessor in _preprocessors)
                {
                    if (gridItemsProcessor.GetType() == typeof(ExportGridItemsProcessor<T>))
                    {
                        _exportUrl = ((ExportGridItemsProcessor<T>)gridItemsProcessor).DownloadUrl;
                        return _exportUrl;
                    }
                }


                return _exportUrl;
            }
            set
            {
                _exportUrl = value;
            }
        }
And at the end of _Grid.cshtml Viewplace this code
@if (Model.IsExport)
{
    Response.Redirect(Model.ExportUrl);
    return;
}
Oct 9, 2016 at 11:06 AM
I hope i didn't miss anything, if someone face problem with this. Do let me know, i'll try my best to help you out.
Oct 12, 2016 at 1:03 PM
Edited Oct 12, 2016 at 1:31 PM
Thanks Khaternakid for the code snippet.

While compiling the GridMVC code I got an error because of the below statement
private IGridSettingsProvider _settings;
...
currentExportItemsProcessor = new ExportGridItemsProcessor<T>(this, _settings.ExportSettings); //Added
Since its not part of the Interface...

Although I'm halfway through copying the code :) and implementing I was wondering is there a way to export only the displayed grid column on button click ?
If I can access the grid in controller then its possible but not sure how...

Lastly I'm getting error after placing the code in _grid.cs.html
'IGrid' does not contain a definition for 'IsExport' and no extension method 'IsExport' accepting a first argument of type 'IGrid' could be found 
It just looks like I'm not using correctly, would it be possible for you to create a separate project and share this with myself and community.

... Thanks a lot
Oct 12, 2016 at 1:20 PM
Edited Oct 12, 2016 at 1:21 PM
I tried my best to put all the changes that i made, but i missed something, here is below


Update the IGrid.cs, add these two lines at the bottom
public interface IGrid
    {
....
....
....
        bool IsExport { get; }

        string ExportUrl { get; }

}
I hope this is the only missing thing.

As far as i know, we have three options to export, these are
Displayed Data(Filter Applied),
All Data including Paging (Filter Applied)
And All Data including Paging (without filter)



But accessing data in the controller, i didn't find anything. Maybe after some workaround we can get this done.

Regards
Oct 12, 2016 at 1:45 PM
I'm creating a separate project. I've also updated in the patches

https://gridmvc.codeplex.com/SourceControl/list/patches
Oct 13, 2016 at 11:59 AM
khaternakid wrote:
I'm creating a separate project. I've also updated in the patches

https://gridmvc.codeplex.com/SourceControl/list/patches
Thanks Katernakid for code. It works like a charm and I was able to implement it smoothly.

Never the less I get an exception after export to excel is completed and code returns to displayed the grid again.
Error Message: Server cannot append header after HTTP headers have been sent.
Also not able to find the property to set the 'Export only displayed columns all pages - basically 2 option from your list "All Data including Paging (Filter Applied)"

Many Thanks for helps me out.
Oct 16, 2016 at 7:11 AM
Hi Singhswat,

I'm not facing this error, maybe this line in _grid.cshtml

Response.Redirect(Model.ExportUrl); will be making this header issue

can you check your DownloadUrl = "~/content/module/exports/document", that code is generating excel file or not?

From my previous comment
As far as i know, we have three options to export, these are
Displayed Data(Filter Applied),
All Data including Paging (Filter Applied)
And All Data including Paging (without filter)
I meant i've implemented only the 2nd one i.e. All Data Including Paging (Filter Applied). But WE CAN implement the others also, because when i was working i saw the code where we can access the rest.


Can you tell me that this issue that you are facing is generated in the source code that i've uploaded in the patches or in your source code?

Regards
Oct 17, 2016 at 9:40 AM
Thanks Khaternakid for the reply.

Regarding - Exporting only displayed column on the grid: I found a cheat code. I edited the template that was being generated by export library and removed the columns that I didn't require and it worked nicely.

Now, just battling with header issue.... I'm from asp.net world and mvc is like going to Mars with friends :)
Oct 17, 2016 at 11:23 AM
Well that's good,

Regarding the header issue, can you upload the code of that page here??

try to check this solution

http://stackoverflow.com/questions/34270192/server-cannot-append-header-after-http-headers-have-been-sent-exception-at-html


also, please tell me that the source code that i uploaded, did you try to build that one and export it?

I was also used to work in asp.net, but recently i started with MVC and i love it.
Oct 17, 2016 at 12:57 PM
I'm using your code with only modification as below... i.e. instead of drop down I give my users a buttonclick to export.

As you suggested if I used Redirect(@Model.ExportUrl); then I get a compile time error The name 'Redirect' does not exist in the current context. I believe its because its part of Controller namespace.

I'm not sure what to do ....
@using System.Web.Mvc
@using GridMvc.Columns
@using GridMvc.Pagination
@model GridMvc.IGrid
@if (Model == null) { return; }



@if (Model.RenderOptions.RenderRowsOnly)
{
    @RenderGridBody();
}
else
{
    <div class="grid-mvc" data-lang="@Model.Language" data-gridname="@Model.RenderOptions.GridName" data-selectable="@Model.RenderOptions.Selectable.ToString().ToLower()" data-multiplefilters="@Model.RenderOptions.AllowMultipleFilters.ToString().ToLower()">
        <div class="grid-wrap">
            <table class="table table-striped grid-table">
                @* Draw grid header *@
                <thead>
                    @RenderGridHeader()
                </thead>
                <tbody>
                    @RenderGridBody()
                </tbody>
            </table>
            @RenderGridFooter()
        </div>
    </div>
}
@helper RenderGridBody()
{
if (!Model.ItemsToDisplay.Any())
{
        <tr class="grid-empty-text">
            <td colspan="@Model.Columns.Count()">
                @Model.EmptyGridText
            </td>
        </tr>
}
else
{
    foreach (object item in Model.ItemsToDisplay)
    {
            <tr class="grid-row @Model.GetRowCssClasses(item)" @Model.GetRowAtr(item)>
                @foreach (IGridColumn column in Model.Columns)
                {
                    @column.CellRenderer.Render(column, column.GetCell(item))
                }
            </tr>
    }
}
}
@helper RenderGridHeader()
{
    <tr>
        @foreach (IGridColumn column in Model.Columns)
        {
            @column.HeaderRenderer.Render(column)
        }
    </tr>
}
@helper RenderGridFooter() __Modified__
{
    <div class="grid-footer">   
        @if (Model.RenderOptions.ShowGridItemsCount)
        {
            <div class="grid-itemscount">
                <span class="grid-itemscount-label">@Model.RenderOptions.GridCountDisplayName:</span>
                <span class="grid-itemscount-caption">@Model.ItemsCount</span>
            </div>
        }
        @if (Model.EnablePaging && Model.Pager != null)
        {
            @Html.Partial(Model.Pager.TemplateName, Model.Pager)
        }

    </div>
}

@if (Model.IsExport)
{
    return  Redirect(Model.ExportUrl); __Modified__
}
Stack trace details
   at System.Web.HttpResponse.AppendHeader(String name, String value)
   at System.Web.HttpResponseWrapper.AddHeader(String name, String value)
   at System.Web.Helpers.AntiXsrf.AntiForgeryWorker.GetFormInputElement(HttpContextBase httpContext)
   at System.Web.Helpers.AntiForgery.GetHtml()
   at System.Web.Mvc.HtmlHelper.AntiForgeryToken()
   at ASP._Page_Views_Shared__LoginPartial_cshtml.Execute() in _LoginPartial.cshtml:line 9
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
   at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName)
   at ASP._Page_Views_Shared__TopNavBar_cshtml.Execute() in _TopNavBar.cshtml:line 20
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
   at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName)
   at ASP._Page_Views_Shared__Layout_cshtml.Execute() in _Layout.cshtml:line 17
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.WebPages.WebPageBase.<>c__DisplayClass3.<RenderPageCore>b__2(TextWriter writer)
   at System.Web.WebPages.HelperResult.WriteTo(TextWriter writer)
   at System.Web.WebPages.WebPageBase.Write(HelperResult result)
   at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body)
   at System.Web.WebPages.WebPageBase.PopContext()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
   at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Oct 19, 2016 at 4:51 AM
Yes you are right, using Redirect is giving a compile error, but i'm unable to generate the below error :(
Error Message: Server cannot append header after HTTP headers have been sent.
I'm still trying to generate this error, to find a solution for this.
Oct 19, 2016 at 11:29 AM
Thanks Khaternakid.

To my surprise I get this error only on my dev box in UAT env it works like a charm.... so I'm wondering what will happen in Prod :)
Oct 20, 2016 at 6:30 AM
Try to check the difference in environment like MVC version, .Net framework, IIS etc.

But one thing i'm sure, this @Html.AntiForgery is making problem in your code.
at System.Web.HttpResponse.AppendHeader(String name, String value)
   at System.Web.HttpResponseWrapper.AddHeader(String name, String value)
   at System.Web.Helpers.AntiXsrf.AntiForgeryWorker.GetFormInputElement(HttpContextBase httpContext)
   at System.Web.Helpers.AntiForgery.GetHtml()
Try to remove this and check.
Oct 20, 2016 at 6:41 AM
or can you upload here your controller & view code?
Nov 24, 2016 at 4:04 PM
Hi Khaternakid, Thanks for the code and helping me out.
Dec 8, 2016 at 11:55 AM
Hi Khaternakid,

I'm relatively new to MVC and I've managed to add Exporter and your code to my project. Problem is I'm having trouble finding the Export Options function you listed in your patch notes:
3- Export Options : this will add an export button at the end of grid, which will export the grid data to pdf, excel etc.
I've found the other 2 features:
1 - SetRawAtr(string) : it will set the raw attr
2- TableId(string) : it will set tabel id
Would you be able to give a quick example of controller and view code to use the export function?

Many Thanks
Dec 13, 2016 at 3:49 AM
Edited Dec 13, 2016 at 3:49 AM
Hi,

If i'm not getting you wrong you are expecting to use the export function like this:
@Html.Grid(Model).Named("ordersGrid").TableId("data-table").Columns(columns =>
    {
        /* Grid Columns */
     

    }).SetRowCssClasses(...).SetRowAtr(....).EXPORT(???)
If yes, then this is not the case. From the word FUNCTIONALITIES i meant NEW FEATURES.

Yes, # 1 & 2 are functions i.e SetRawAtr, TableId.. but this export is not a function, which means after implementing the code that i've given above, for each grid it should automatically display the export button. If you are unable to see that button, maybe a css not problem or something...

you can download this complete source code which i uploaded in the patch list, try to build and see does it work with you or not?

https://www.codeplex.com/Download?ProjectName=gridmvc&DownloadId=1613110


Regards
Dec 14, 2016 at 8:06 AM
Hi Khaternakid,

Thanks for your reply.

Indeed I was expecting the functionality as you described in your above example.

I've downloaded and ran your source code and was able to see the export button with all the options. I need to investigate further why I'm not seeing it my project. Could be my css as I'm using a bootswatch theme and occasionally some buttons render as white on white or it could be that I've missed something else. If I get stuck I'll come back to you.

Thanks again
Jan 5 at 7:57 PM
Hi Khaternakid,

Thanks for providing export functionality in the grid. Is there a way to export only visible columns and hide invisible columns from not getting exported?
Jan 9 at 12:20 PM
Hi,

Yes, you can adjust the template and for the export. In my source code i've mentioned the path
~/content/module/templates
you can find the template of excel,pdf etc and adjust it as per your requirement. (If you don't find the template, try to export the data, it will automatically create template)

Regards
Feb 8 at 5:05 PM
Hi Khaternakid,

have one more question on Export functionality. I did exactly the same as the same as mentioned in this post for export functionality and every thing works fine on my local box. But when I deploy the application on dev server I get the following error while using Export functionality.

Could not load file or assembly 'System.Web.Razor,Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I am using 'System.Web.Mvc, Versoin 5.2.3.0' and "System.Web.Razor, Version= 3.0.0.0' in my development. Any idea why this issue happens on Server but works fine on my local box.
Mar 1 at 3:44 AM
Hi Rama,
I think this issue does not belong to GridMvc, but i've googled it and found this

http://stackoverflow.com/questions/11000506/could-not-load-file-or-assembly-system-web-webpages-razor-version-2-0-0-0

http://stackoverflow.com/questions/15874366/could-not-load-file-or-assembly-system-web-razor-or-one-of-its-dependencies

This is something related to Asp.net MVC dll version difference as it is clear from your message.

But i think you might have solved it, sorry for being late, i've no idea why i'm not receiving email when someone posts here. Even though i've tick the checkbox for notification.

Regards
Aug 17 at 5:57 PM
Edited Aug 17 at 5:58 PM
Hi Khaternakid/singhswat,

Question 1:

Regarding - Exporting only displayed column on the grid: I tried singhswat solution to edit the template. How can we format the template (tags & tag properties) for look and feel, i tried html tags but it wont work?
Also i want to apply the conditions to show/hide a column, where do you think the condition should go? either in template item file or in ExportGridItemsProcessor.cs?

Question 2: If we have two grids in a page, how can we handle the print option to select the grid we want?

Please Advice

Regards