我在我的網頁上有一個網格視圖,我想將它導出到Excel工作表, 下面是我寫的代碼來完成此任務,我在這裏已經傳遞數據集的方法,以網格結合和btnExcelExport
是將導出網格內容到Excel工作表的按鈕: -Sys.WebForms.PageRequestManagerParserErrorException:從服務器收到的消息無法解析
private void BindGridView(DataSet ds)
{
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
GVUserReport.DataSource = ds;
GVUserReport.DataBind();
btnExcelExport.Visible = true;
}
}
}
protected void btnExcelExport_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition","attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GVUserReport.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
return;
}
現在,當我調試我發現,網格綁定成功,但試圖將其導出到Excel時,我得到此錯誤:
"Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed."
什麼,如果腳本管理器是在母版頁? –
@ShivaPareek它應該以任何方式工作,但如果它不放置一個ScriptManagerProxy並使用它! – Peter
我已經使用了這種方法,整個頁面都被重新加載。 IsPostBackProperty = false會導致不導出事件導出?可能是什麼問題? –