0

Hi,
I'm using the following code to download to excel from my datagrid. when i click on the button, the entire screen goes blank. Please help me out..

Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
Common cmn = new Common();
cmn.ClearControls(dgridProject);
dgridProject.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by kapil.goyal
0

i m providing a code made necessary change at ur end.


Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=MyExcel.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
Dim sw As StringWriter = New StringWriter
Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
dgdfiles.RenderControl(htw)
Response.Write(sw.ToString())
Response.End()

dgdfiles is the datagrid control id.

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.