Hi,
Refering to your article on exporting the gridview to Word/Excel/PDF/CSV, I modified to code to populate the GV dynamically coz they have different data and different columns as per the selection. But after the data population, when I try to export the data it does not export any data instead for eg. in Word it just export.
Any help would be appreciated.
The code is pasted below.
**** The below is the code for populating GV ********
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As DataTable = GetData()
Dim dcol As DataColumn
Dim bfields As BoundField
GridView1.Columns.Clear()
For Each dcol In dt.Columns
bfields = New BoundField
bfields.DataField = dcol.ColumnName
bfields.HeaderText = dcol.ColumnName
GridView1.Columns.Add(bfields)
Next
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
**** Below Code is from your samples for exporting GV data ******
Protected Sub btnExportWord_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Response.Clear()
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.doc")
Response.Charset = ""
Response.ContentType = "application/vnd.ms-word "
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
GridView1.AllowPaging = False
GridView1.DataBind()
GridView1.RenderControl(hw)
Response.Output.Write(sw.ToString())
Response.Flush()
Response.End()
End Sub