日期:2014-05-17 浏览次数:20506 次
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void btnExcelError_Click(object sender, EventArgs e)
{
GridViewToExcel(RecordToolbar1);
}
public void GridViewToExcel(GridView _GridView)
{
Response.Clear();
Response.BufferOutput = true;
//设定输出的字符集
Response.Charset = "GB2312";
//假定导出的文件名为MyExcelFile.xls
Response.AppendHeader("Content-Disposition", "attachment;filename=MyExcelFile.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo);
System.Web.UI.HtmlTextWriter textWriter = new System.Web.UI.HtmlTextWriter(stringWriter);
_GridView.RenderControl(textWriter);
//把HTML写回浏览器
Response.Write(stringWriter.ToString());
Response.End();
}
<asp:GridView ID="RecordToolbar1" runat="server" AutoGenerateColumns="False" Width="98%"
Height="60px" text-align="center" CssClass="grid" EnableViewState="False">
<HeaderStyle CssClass="gridHeader" />
<PagerSettings Visible="false" />
<RowStyle CssClass="gridItem" />
<Columns>
&nbs