Danish Habib

Danish Habib

  • NA
  • 694
  • 231.8k

problem when exporting gridview content into excel

Jun 8 2015 3:04 AM
I have a Master page and a child page in child page i have  a gridview showing the record set i want to export and print this records so i am using that code on button click event ...
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)
grdUserReports.AllowPaging = False
grdUserReports.DataBind()
grdUserReports.RenderControl(hw)
Response.Output.Write(sw.ToString())
Response.Flush()
Response.End()
 
The highlited row gives error that
"Control 'ctl00_ContentPlaceHolder1_grdUserReports' of type 'GridView' must be placed inside a form tag with runat=server." 
 

Answers (18)