给象我一样的菜鸟们,GridView实用示例源码(可以导出Excel)
最近在学GridView,但是找了很多教程但是都没有实例,特别是导出Excel的
,于是就自己整理写了一个,给象我一样的菜鸟们,如果正在学Asp.net2.0的同僚们可以看看阿!高手不要见笑哦!
GridView实用源码(可以导出Excel) VS2005中GridView的自定义分页,单选、多选、排序、自增列及可以导出Excel的简单应用源码多选时,只有全部选中时“多选”才选中
导出Excel部分的源码
//导出到Execl
protected void Button3_Click(object sender, EventArgs e)
{
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
protected void Button3_Click(object sender, EventArgs e)
{
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
下载地址
liudao-MVP