Critical Developers

Programmers Knowledge Base

Export Multiple GridView to Excel

Dim heading As String = ""
Dim heading1 As String = ""
heading = "<center><h1>All-Members</h1></center><br />"
Dim filename As String = "All-Grid-Details" & CStr(Date.Today.Day & Date.Today.ToString("MM") & Date.Today.Year) & ".xls"
Dim form As New HtmlForm()
GridView1.AllowPaging = False
BindGrid1()
GridView2.AllowPaging = False
BindGrid2()
GridView3.AllowPaging = False
BindGrid3()
GridView4.AllowPaging = False
BindGrid4()
GridView5.AllowPaging = False
BindGrid5()
Response.ClearContent()
Dim attachment As String = "attachment; filename=" & filename
Response.ClearContent()
Response.AddHeader("content-disposition", attachment)
Response.ContentType = "application/ms-excel"
Dim stw As New StringWriter()
Dim htextw As New HtmlTextWriter(stw)
form.Controls.Add(Label1)
form.Controls.Add(GridView1)
form.Controls.Add(Label2)
form.Controls.Add(GridView2)
form.Controls.Add(Label3)
form.Controls.Add(GridView3)
form.Controls.Add(Label4)
form.Controls.Add(GridView4)
form.Controls.Add(Label5)
form.Controls.Add(GridView5)
Me.Controls.Add(form)
form.RenderControl(htextw)
Response.Write(heading)
Response.Write(stw.ToString())
Response.End()

Comments (3) -

  • Jacques Buhrke

    30-01-2015 03:17:58 | Reply

    Hi there! I know this is somewhat off topic but I was wondering if you knew where I could find a captcha plugin for my comment form? I'm using the same blog platform as yours and I'm having difficulty finding one? Thanks a lot!|

  • Ebony Shawl

    31-01-2015 00:21:47 | Reply

    Very good information. Lucky me I ran across your blog by accident (stumbleupon). I've book marked it for later!|

  • Denny

    12-02-2015 04:25:14 | Reply

    Quite good internet site thanks so much to your time in writing the posts for all of us to learn about.

Loading