有时候我们需要把把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();