我可以将gridview导出到excel,但我不想提示窗口询问文件名和路径,如何禁用它? 此外,如何设置保存文件的路径?
由于 乔
以下是我的代码:
Private Sub ExportGridView()
Dim filename As String
filename = ddlMonth.SelectedValue & "-" & ddlYear.SelectedValue
Dim attachment As String = "attachment; filename=" & filename & ".xls"
Response.ClearContent()
Response.Buffer = True
Response.Charset = "UTF-8"
Response.AddHeader("content-disposition", attachment)
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8")
Me.EnableViewState = False
Response.ContentType = "application/ms-excel"
Dim sw As New StringWriter()
Dim htw As New HtmlTextWriter(sw)
'Turn off the paging for export
Gridview1.DataSource = Session("dt")
Gridview1.AllowPaging = False
Gridview1.DataBind()
GridView1.RenderControl(htw)
Response.Write(sw.ToString())
Response.[End]()
'Turn on the paging after export
Gridview1.DataSource = Session("dt")
Gridview1.AllowPaging = True
Gridview1.DataBind()
End Sub
答案 0 :(得分:0)
//声明<%= MyMethodCall()%> //在后面的代码中protected String MyMethodCall(){return“Test Value”; }