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();

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.