//FIRST WAY
If GridView1.Rows.Count.ToString + 1 < 65536 Then
GridView1.AllowPaging = "False"
bindgrid1()
Dim tw As New StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Dim frm As HtmlForm = New HtmlForm()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment;filename=" & txtfile.Text & ".xls") Response.Charset = "" EnableViewState = False Controls.Add(frm) frm.Controls.Add(GridView1) frm.RenderControl(hw) Response.Write(tw.ToString()) Response.End()
GridView1.AllowPaging = "True"
bindgrid1()
Else
lblerror.Text = "Too many rows - Export to Excel not possible"
End If
//SECOND WAY
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim oStringWriter As New System.IO.StringWriter
Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
DataGrid1.RenderControl(oHtmlTextWriter)
Response.Write(oStringWriter.ToString())
Response.[End]()
End Sub
No comments:
Post a Comment