将 GridView 导出到 Excel 文件中
protected void btnDaoChu_Click(object sender, EventArgs e){
Response.Clear();
Response.AddHeader("content-disposition","attachment;filename=FileName.xls");
Response.Charset = "gb2312";
Response.ContentType = "application/vnd.xls";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
//GridView1.AllowPaging = false;
//GridViewBind();
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
//GridView1.AllowPaging = true;
//GridViewBind();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Attributes.Add("style", "vnd.ms-excel.numberformat:@;");
}
}
请问我的代码哪里出错了,怎么运行怎么报了“一个只能在执行Render()的过程中调用......”我不知道哪里出错了
请路过的朋友来看下了。
谢谢啊!!!