Asp.NET Tutorials
Home > 控件使用 > 把DataGrid导出到Excel
把DataGrid导出到Excel

有时候我们需要把把datagrid连同数据导出到excel来用,以下是具体的实现代码....

youedatagrid.datasource=yourgetdatasourcemethord()

youedatagrid.databind();


Response.Clear();
Response.Buffer=true;
Response.ContentType="application/vnd.ms-excel";
Response.Charset="";
this.EnableViewState=false;


stringwriter  sw=new  stringwriter();
HtmlTextWriter  htw=new  HtmlTextWriter(sw);
YoueDataGrid.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();

 

Add by : Huobazi (2005-7-05:07:06)