.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> VB.Net >> Post New QuestionBookmark and Share Subscribe to Forum

vb.net

Posted By: Naresh     Posted Date: February 28, 2010    Points:2   Category :VB.Net
hi,

i want to export the grid view data to excel. i tried the coding, but error occurs.
"'GridView' must be placed inside a form tag with runat=server. "

i placed the grid view inside master page.
the coding i tried is,

Protected Sub EXporttoExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim stringWrite As IO.StringWriter = New IO.StringWriter
Dim htmlWrite As HtmlTextWriter = New HtmlTextWriter(stringWrite)
gvResult.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()
End Sub




malathy

Responses
Author: Amit Mehra             
Posted Date: March 01, 2010     Points: 5   

HI,

Make Sure you have added Form tag inside master page.

this error throws when any asp.net server control is being used without <form> tag

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Naresh             
Posted Date: March 01, 2010     Points: 5   

hi Amit,

I had placed the grid view in Content Placeholder, where i attached the form with a master page.

Yes the form is placed inside the master page.

Thanks
Naresh
Author: Amit Mehra             
Posted Date: March 01, 2010     Points: 5   

Hi malathy,

Do not keep anything in side Content Placeholder in master page..Place GridView somewhere else in Master Page and see.

Because content Place hosder is the pace where all the control reside which uses (another page) this master page

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Naresh             
Posted Date: March 01, 2010     Points: 5   

Hi Amit,

No i can't move the grid view out of content Placeholder.

Thanks
Naresh
Author: Naresh             
Posted Date: March 01, 2010     Points: 5   

Hi ,

I tried the following coding and now the code works.

Protected Sub Bt_Excel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Bt_Excel.Click
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim stringWrite As IO.StringWriter = New IO.StringWriter
Dim htmlWrite As HtmlTextWriter = New HtmlTextWriter(stringWrite)
gvResult.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()
End Sub
// If we get the error 'GridView' must be placed inside a form tag with runat=server. " To overcome the error we have to use the below code,

Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)

End Sub


Thanks

Thanks
Naresh


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend