我的是动态添加GRIDview,我有3个DropDownList,我想在点点导出后,根据条件,导出到EXCEL,代码如下 private void ToExcel(Control ctl, string FileName)
{
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
} private void toExcelClk()
{
GridView1.AllowPaging = false;
GridView1.AllowSorting = false;
bind();
ToExcel(GridView1, "OFS_Data.xls");
GridView1.AllowPaging = true;
GridView1.AllowSorting = true;
GridView1.DataBind();
}
如果不条件导出没有问题,如果加了条件以后导出只显示<div></div>,请高手帮忙
{
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
} private void toExcelClk()
{
GridView1.AllowPaging = false;
GridView1.AllowSorting = false;
bind();
ToExcel(GridView1, "OFS_Data.xls");
GridView1.AllowPaging = true;
GridView1.AllowSorting = true;
GridView1.DataBind();
}
如果不条件导出没有问题,如果加了条件以后导出只显示<div></div>,请高手帮忙
解决方案 »
- 急求:导出后的鼠标样式改变
- 各位大神和大婶们,一个架构问题,深也不深,看我道来,求高手高高手把小弟解答。
- asp.net页面<%被转换成="<%的问题
- gridview 传递参数
- 100 分!! 在vs2005 下应用 webdiyer 的分页控件,不用存储过程,只是 sql 语句方法,为什么分页后数据不连续,请看...
- ASPNET添加域用户失败问题,急~~~
- 一段html标签加上后DataGrid的删除功能就失效,去掉就管用了,奇怪呀!!
- datalist 或 repeater 可以增加鼠标效果吗?
- 正则表达式问题,如果使=右边的内容替换左边的内容
- 关于从一个网站页面中抓取图片的问题。
- asp.net如何便利页面上所有文本框?
- vs2005+AJAX Extension1.0 + .NET Framework 3.5 + ASP.NET2.0 +AJAX Control Tools 3.0调试出错 , 求正解!
{
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
} private void toExcelClk()
{
GridView1.AllowPaging = false;
GridView1.AllowSorting = false;
bind();
ToExcel(GridView1, "OFS_Data.xls");
GridView1.AllowPaging = true;
GridView1.AllowSorting = true;
bind(); ///////////////这个地方改一下
}