01.
public
override
void
VerifyRenderingInServerForm(Control control)
02.
{
03.
}
04.
05.
private
void
ExportToExcel(
string
strFileName, GridView dg)
06.
{
07.
Response.Clear();
08.
Response.Buffer =
true
;
09.
Response.ContentType =
"application/vnd.ms-excel"
;
10.
Response.Charset =
""
;
11.
this
.EnableViewState =
false
;
12.
System.IO.StringWriter oStringWriter =
new
System.IO.StringWriter();
13.
System.Web.UI.HtmlTextWriter oHtmlTextWriter =
new
System.Web.UI.HtmlTextWriter(oStringWriter);
14.
dg.RenderControl(oHtmlTextWriter);
15.
Response.Write(oStringWriter.ToString());
16.
Response.End();
17.
}
18.
19.
private
void
ExportToPDF(
string
strFileName, GridView dg)
20.
{
21.
22.
Response.Clear();
23.
Response.Buffer =
true
;
24.
Response.ContentType =
"application/vnd.PDF"
;
25.
Response.Charset =
""
;
26.
this
.EnableViewState =
false
;
27.
System.IO.StringWriter oStringWriter =
new
System.IO.StringWriter();
28.
System.Web.UI.HtmlTextWriter oHtmlTextWriter =
new
System.Web.UI.HtmlTextWriter(oStringWriter);
29.
GridView1.RenderControl(oHtmlTextWriter);
30.
Response.Write(oStringWriter.ToString());
31.
Response.End();
32.
33.
34.
}
35.
36.
protected
void
Button1_Click(
object
sender, EventArgs e)
37.
{
38.
ExportToExcel(
"Report.xls"
, GridView1);
39.
40.
41.
}