摘要:匯出excel功能:VS2005
匯出excel功能:
型別 'GridView' 的控制項 'GridView1' 必須置於有 runat=server 的表單標記之中。
問題一:可以在您的CodeFile中加入以下這段來解決
public override void VerifyRenderingInServerForm(Co
{
//處理'GridView' 的控制項 'GridView' 必須置於有 runat=server 的表單標記之中
}
問題二:如果您的GridView沒有設定分頁,應該就可以正常
RegisterForEventValidation 只能在 Render(); 期間呼叫這個問題,
可以設定aspx原始檔中<%Page%>的以下兩個設定解決:
protected void Button1_Click(object sender, EventArgs e)
{
if (GVResult.Rows.Count + 1 < 65536)
{
StringWriter tw = new StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(t
HtmlForm frm = new HtmlForm();
Response.Charset = "utf-8";
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-di
GVResult.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
else
Response.Write("Too many rows - Export to Excel not possible(65536)");
}