0

hi,

i have a web page on which i am displaying data in gridview control from database.i want to generate the excel report of this grid data. i am using the following code behind button click. it is working well.

private void ExportGridView()
{
     string attachment = "attachment; filename=invalidproductdata.xls";
     Response.ClearContent();
     Response.AddHeader("content-disposition", attachment);
     Response.ContentType = "application/ms-excel";
     StringWriter sw = new StringWriter();
     HtmlTextWriter htw = new HtmlTextWriter(sw);
     myGridView.RenderControl(htw);
     Response.Write(sw.ToString());
     Response.End();
}

but the problem is that i want to take this code into my code class in business logic layer for reuse purpose.but when i put this method in logic layer class it creates an error. the error is " Response does not exist in the current context ".
plz help me how can i resolve this issue.

Thanks and Best Regards,
Nice Candy

Edited by __avd: Added [code] tags.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by __avd
0

Use HttpContext.Current property.

..
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
..
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.