Answers
protected void PageLoad(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = new SHS.BLL.shengOnline().GetAllList();
gvUser.DataSource = ds;
gvUser.DataBind();
}
}
public override void VerifyRenderingInServerForm(Control control) //重载方法
{
//base.VerifyRenderingInServerForm(control);
}
protected void LinkButton1Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
//gaoyang [10/21/2006] 经测试如果设置为 GetEncoding("GB2312"),导出的文件将会出现乱码。
Response.ContentEncoding = System.Text.Encoding.UTF7;
//设置输出文件类型为excel文件
Response.ContentType = "application/ms-excel";
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.gvUser.RenderControl(oHtmlTextWriter);
Response.Output.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
}
<font color="red">-------------------------------------------</font>
这是 将GridView中的导出到Excel,你可以进行更改