本文介绍了在母版页中导出到Excel Gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有要求,即在母版页中导出到Excel GridView数据.在尝试导出时,出现 sys.webforms.pagerequestmanagerparsererrorexception 错误.任何人都可以帮助我解决这个问题.我尝试了如下不同方式
1.
DataTable dt = BindCompanies(); string attachment = "attachment; filename=Employee.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/vnd.ms-excel"; string tab = ""; foreach (DataColumn dc in dt.Columns) { Response.Write(tab + dc.ColumnName); tab = "\t"; } Response.Write("\n"); int i; foreach (DataRow dr in dt.Rows) { tab = ""; for (i = 0; i < dt.Columns.Count; i++) { Response.Write(tab + dr[i].ToString()); tab = "\t"; } Response.Write("\n"); } Response.End();
2.
string attachment = "attachment; filename=Export.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); // Create a form to contain the grid HtmlForm frm = new HtmlForm(); gv.Parent.Controls.Add(frm); frm.Attributes["runat"] = "server"; frm.Controls.Add(gv); frm.RenderControl(htw); //GridView1.RenderControl(htw); Response.Write(sw.ToString()); Response.End();
问候,
Jeevan.
解决方案
Hi All,
I have requirement i.e export to excel gridview data in the master pages. While i am trying to export i am getting sys.webforms.pagerequestmanagerparsererrorexception error. Any one please help me out regarding this issue. I have tried in different ways like as follows
1.
DataTable dt = BindCompanies(); string attachment = "attachment; filename=Employee.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/vnd.ms-excel"; string tab = ""; foreach (DataColumn dc in dt.Columns) { Response.Write(tab + dc.ColumnName); tab = "\t"; } Response.Write("\n"); int i; foreach (DataRow dr in dt.Rows) { tab = ""; for (i = 0; i < dt.Columns.Count; i++) { Response.Write(tab + dr[i].ToString()); tab = "\t"; } Response.Write("\n"); } Response.End();
2.
string attachment = "attachment; filename=Export.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); // Create a form to contain the grid HtmlForm frm = new HtmlForm(); gv.Parent.Controls.Add(frm); frm.Attributes["runat"] = "server"; frm.Controls.Add(gv); frm.RenderControl(htw); //GridView1.RenderControl(htw); Response.Write(sw.ToString()); Response.End();
Regards,
Jeevan.
解决方案
这篇关于在母版页中导出到Excel Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!