摘要:不能轉Excel
1. w.LoadTbToBind(IsPostBack)
gv.DataSource = w.vTb
w.vTB必須為public
Load 後必須再指定gv.Datasource
2. toExcel 不要databind
01.Public Sub ToExcel()
02.
03. Response.Clear()
04. Response.Buffer = True
05. Response.Charset = "BIG5"
06. Response.AddHeader("content-disposition", "attachment;filename=" + """" + "pc.xls" + """")
07. Response.ContentType = "application/vnd.ms-excel"
08. gv.AllowPaging = False
09. 'gv.DataBind()
10. gv.EnableViewState = False
11.
12. Dim objStringWriter As New StringWriter
13. Dim objHtmlTextWriter As New UI.HtmlTextWriter(objStringWriter)
14. '--註解:或是寫成 Dim objHtmlTextWriter As UI.HtmlTextWriter = New UI.HtmlTextWriter(objStringWriter)
15.
16. gv.RenderControl(objHtmlTextWriter)
17. '處理'GridView' 的控制項 'GridView' 必須置於有 runat=server 的表單標記之中
18. 'must add VerifyRenderingInServerForm
19.
20. ' 切換到.aspx原始碼在頁頭<@ page....> 加入
21. 'EnableEventValidation = "false" AutoEventWireup="true"
22.
23. Response.Write(objStringWriter.ToString())
24. Response.End()
25. gv.AllowPaging = True
26. 'gv.DataBind()
27.
28.End Sub
02.
03. Response.Clear()
04. Response.Buffer = True
05. Response.Charset = "BIG5"
06. Response.AddHeader("content-disposition", "attachment;filename=" + """" + "pc.xls" + """")
07. Response.ContentType = "application/vnd.ms-excel"
08. gv.AllowPaging = False
09. 'gv.DataBind()
10. gv.EnableViewState = False
11.
12. Dim objStringWriter As New StringWriter
13. Dim objHtmlTextWriter As New UI.HtmlTextWriter(objStringWriter)
14. '--註解:或是寫成 Dim objHtmlTextWriter As UI.HtmlTextWriter = New UI.HtmlTextWriter(objStringWriter)
15.
16. gv.RenderControl(objHtmlTextWriter)
17. '處理'GridView' 的控制項 'GridView' 必須置於有 runat=server 的表單標記之中
18. 'must add VerifyRenderingInServerForm
19.
20. ' 切換到.aspx原始碼在頁頭<@ page....> 加入
21. 'EnableEventValidation = "false" AutoEventWireup="true"
22.
23. Response.Write(objStringWriter.ToString())
24. Response.End()
25. gv.AllowPaging = True
26. 'gv.DataBind()
27.
28.End Sub