title: Gridview has a runat="server" tag
body: <p>I have added iTextSharp to "Project>...Add References" and added them to using:</p>
  
  <pre><code>using iTextSharp.text;
  using iTextSharp.text.html.simpleparser;
  using iTextSharp.text.pdf;  
  </code></pre>
  
  <p>I have a runat="server" tag already in aspx:</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server"&gt;&lt;/asp:GridView&gt;
  </code></pre>
  
  <p>But I get the error code at line "GridView1.RenderControl(hw);</p>
  
  <pre><code> Control 'MainContent_GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
  </code></pre>
  
  <p>Button1_Click Code:</p>
  
  <pre><code>protected void Button1_Click(Object sender,System.EventArgs e)
      {
          string connStr = ConfigurationManager.ConnectionStrings["PDFMDF"].ConnectionString;
          DataSet ds = new DataSet();
          try
          {
              string cmdStr = "SELECT * FROM [GridviewTable];";
              using (SqlConnection conn = new SqlConnection(connStr))
              {
                  using (SqlCommand cmd = new SqlCommand(cmdStr, conn))
                  {
                      conn.Open();
                      using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                      {
                          da.Fill(ds);
                          GridView1.DataSource = ds;
                          GridView1.DataBind();
                      }
                      conn.Close();
                      cmd.Dispose();
                      conn.Dispose();
                  }
              }
          }
          catch  (Exception ex)
          {
              TextBox1.Text = ex.ToString();
          }
  
          Response.ContentType = "application/pdf";
          Response.AddHeader("content-disposition", "attachment;filename=this.pdf");
          Response.Cache.SetCacheability(HttpCacheability.NoCache);
          StringWriter sw = new StringWriter();
          HtmlTextWriter hw = new HtmlTextWriter(sw);
          GridView1.AllowPaging = false;
          GridView1.RenderControl(hw);
          StringReader sr = new StringReader(sw.ToString());
          Document PDFdoc = new Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F);
          iTextSharp.text.html.simpleparser.HTMLWorker htmlparser =   new iTextSharp.text.html.simpleparser.HTMLWorker(PDFdoc);
          PdfWriter.GetInstance(PDFdoc, Response.OutputStream);
          PDFdoc.Open();
          htmlparser.Parse(sr);
          PDFdoc.Close();
          Response.Write(PDFdoc);
          Response.End();
      }
  </code></pre>