DataGrid带分页时向excel倒入数据出现错误 当把DataGrid的allowpaging设置为"true"时,DataGrid中的数据就无法倒入到excel中,提示错误:"类型“DataGridLinkButton”的控件“DataGrid1__ctl19__ctl1”必须放在具有 runat=server 的窗体标记内。" DataGrid的allowpaging设置为"true"时,数据可以倒入到excel.期待高手出手.... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 要先取消分页,再导,附了相关代码,你参考一下: private void btExportExcel_Click(object sender, System.EventArgs e) { Response.ContentType = "application/vnd.ms-excel"; Response.Charset="GB2312"; Response.AppendHeader("Content-Disposition","attachment;filename=UpdateDataLog.xls"); Response.ContentEncoding=System.Text.Encoding.UTF7; //设置输出流为简体中文 this.EnableViewState = false; System.IO.StringWriter sw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw); int nCur = this.dgViewLog.CurrentPageIndex; int nSize = this.dgViewLog.PageSize; this.dgViewLog.AllowPaging = false; this.BindGrid(); // this.dgViewLog.Columns[0].Visible =false;// this.dgViewLog.Columns[5].Visible =false;// this.dgViewLog.Columns[6].Visible =false;// this.dgViewLog.Columns[7].Visible =false;// this.dgViewLog.Columns[8].Visible =false; this.dgViewLog.RenderControl(hw);// this.dgViewLog.Columns[0].Visible =true;// this.dgViewLog.Columns[5].Visible =true;// this.dgViewLog.Columns[6].Visible =true;// this.dgViewLog.Columns[7].Visible =true;// this.dgViewLog.Columns[8].Visible =true; //以下恢复分页 this.dgViewLog.AllowPaging = true; this.dgViewLog.CurrentPageIndex = nCur; this.dgViewLog.PageSize = nSize; this.BindGrid(); Response.Write(sw.ToString()); Response.End(); } DataGrid1.AllowPaging = false;//重新绑定//导出到excelDataGrid1.AllowPaging = ture;//再次重新绑定 谢谢上面各位的帮助。项目中要求分页显示,而且往EXCEL或WORD倒入的时候要求分页倒入,就是倒入的格式与DataGrid显示的格式是一样的。 楼主,这样不太可能吧.呵呵.在excel中可以实现点下一页就到另一页的效果吗? excel没办法分页,你只能导excel的时候allowpaging=false;导入完毕之后allowpaging=true; 求WEB页面打印方法! DataGrid与DropDownList数据绑定的问题 大哥,小弟在线恭候您呐。。。 session 关于frameset 通过reflector反编译的Dll文件如何编辑? 怎么在改XML文件下添加记录。(对XML的修改操作) 两个DATATABLE间进行赋值的问题,急!给40 文件上传不了,如何处理文件名 hyperlink imageurl与text属性的问题 asp.net treeview的问题 asp.net开发的wap页面中图片(根据编号,gif)动态调用,但在NOKIA6600中手机中无法显示的问题???
private void btExportExcel_Click(object sender, System.EventArgs e)
{
Response.ContentType = "application/vnd.ms-excel";
Response.Charset="GB2312";
Response.AppendHeader("Content-Disposition","attachment;filename=UpdateDataLog.xls");
Response.ContentEncoding=System.Text.Encoding.UTF7; //设置输出流为简体中文
this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
int nCur = this.dgViewLog.CurrentPageIndex;
int nSize = this.dgViewLog.PageSize;
this.dgViewLog.AllowPaging = false;
this.BindGrid();
// this.dgViewLog.Columns[0].Visible =false;
// this.dgViewLog.Columns[5].Visible =false;
// this.dgViewLog.Columns[6].Visible =false;
// this.dgViewLog.Columns[7].Visible =false;
// this.dgViewLog.Columns[8].Visible =false;
this.dgViewLog.RenderControl(hw);
// this.dgViewLog.Columns[0].Visible =true;
// this.dgViewLog.Columns[5].Visible =true;
// this.dgViewLog.Columns[6].Visible =true;
// this.dgViewLog.Columns[7].Visible =true;
// this.dgViewLog.Columns[8].Visible =true;
//以下恢复分页
this.dgViewLog.AllowPaging = true;
this.dgViewLog.CurrentPageIndex = nCur;
this.dgViewLog.PageSize = nSize;
this.BindGrid();
Response.Write(sw.ToString());
Response.End(); }
//重新绑定//导出到excelDataGrid1.AllowPaging = ture;
//再次重新绑定