Trek Innovations

Thoughts For You

Exporting GridView to Excel Problem When Using Web UserControl:

This article explains how you can export your GridView control to Excel files. If you are working with web user control. Suppose if you are having your gridview in your User Control and you are trying to export the gridview data to some other format some thing like this

protected void _btnReports_Click(object sender, EventArgs e)

{

Response.Clear();

Response.Write(@”<!DOCTYPE HTML PUBLIC “”-//W3C//DTD HTML 4.0 Transitional//EN”">”);

Response.AddHeader(“content-disposition”, “inline;filename=search_topicarea.doc”);

Response.Charset = “”;

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = “application/vnd.doc”;

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

//System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

//Render(htmlWrite);

_gvViewresults.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();

}

Read more

Share This Post No comments

Exporting GridView to Excel ‘GridView’ must be placed inside a form tag

This article explains how you can export your GridView control to Excel files. If you are working with GridView.

Exporting Grid View to Excel Files:

The approach is pretty much the same as it was in Gridview. The following code executes on a button click event.

protected void _btnReports_Click(object sender, EventArgs e)

{

Response.Clear();

Response.Write(@”<!DOCTYPE HTML PUBLIC “”-//W3C//DTD HTML 4.0 Transitional//EN”">”);

Response.AddHeader(“content-disposition”, “inline;filename=search_topicarea.doc”);

Response.Charset = “”;

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = “application/vnd.doc”;

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

//System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

//Render(htmlWrite);

_gvViewresults.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();

}

Read more

Share This Post No comments