GridView导出excel问题
Gridview里面显示的数据是截取的,以 ######...的样式,但是导出excel也会导出不全的数据。我的Gridview是用的PageDataSource类分的页。能不能把PageDataSource的当前索引的数据导出到excel,怎么做? --------------------编程问答-------------------- protected void Page_Load(object sender, EventArgs e){
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=book;Integrated Security=True");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from book", con);
DataTable dt = new DataTable();
da.Fill(dt);
DataGrid1 .DataSource = dt;
DataGrid1.DataBind();
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
//关闭 ViewState
EnableViewState = false;
StreamWriter MyWriter;
//将信息写入字符串
string Directorypath = Server.MapPath("~/2.excel");
MyWriter = new System.IO.StreamWriter(Directorypath);
//在Web窗体页上写出一系列连续的HTML特定字符和文本
HtmlTextWriter MyWeb = new HtmlTextWriter(MyWriter);
//将DataGrid中的内容输出到HtmlTextWriter对象中
DataGrid1.RenderControl(MyWeb);
//把HTML写回浏览器
Response.Write(MyWriter.ToString());
}
这样行的,为什么Gridview就出错了呢?
补充:.NET技术 , ASP.NET