65.9K
CodeProject is changing. Read more.
Home

Export whole page to Excel with infragistics in ASP.NET C#

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Nov 1, 2011

CPOL
viewsIcon

7321

Tip: Change your loop to the following to also support derived classes:foreach (var item in controlList ){ GridView asGridView = item as GridView; if (asGridView != null) { Utilities.RenderControlInExcel(asGridView, workBook); } DetailsView asDetailsView =...

Tip: Change your loop to the following to also support derived classes:

foreach (var item in controlList )
{
    GridView asGridView = item as GridView; 
    if (asGridView != null)
    {
        Utilities.RenderControlInExcel(asGridView, workBook);
    }
    DetailsView asDetailsView = item as DetailsView;
    if (asDetailsView != null)
    {
        detailsRowStart = Utilities.RenderControlInExcel(
            asDetailsView, detailsSheet, detailsRowStart);
    }

Add a using statement to WriteToResponse:

using(System.IO.MemoryStream theStream = new System.IO.MemoryStream()){
//...  code.....
}

The term view.Rows[row].Cells[col]. is used many times. Extract to a variable to improve performance and readability.