Note that there are some explanatory texts on larger screens.

plurals
  1. POUserControl Export GridView to PDF
    primarykey
    data
    text
    <p>I have a <em>UserControl</em> and I'm trying to export my GridView table to a PDF. I am able to do a CSV file just fine, but I get errors when trying to do a PDF. (I am using iTextSharp Library) This is the error I'm getting:</p> <p><strong>"Control 'DoNotAddList_1_GridView1' of type 'GridView' must be placed inside a form tag with runat=server."</strong></p> <p>I have a form tag in my html, and I tried adding it in the ascx file but nothing works. I've found many people getting this error and most everyone suggested adding this to code to the ascx.cs file:</p> <pre><code>public override void VerifyRenderingInServerForm(Control control) { } </code></pre> <p>But that gives me this error <strong>"no suitable method found to override..."</strong></p> <p>I don't know what to do. I haven't been able to find a solution. Please Help!! </p> <pre><code>using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.text.html; using iTextSharp.text.html.simpleparser; public partial class UserControls_DoNotAddListControl : System.Web.UI.UserControl { protected void PDF_Click(object sender, EventArgs e) { Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); GridView1.AllowPaging = false; GridView1.DataBind(); GridView1.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); } protected void CSV_Click(object sender, EventArgs e) { Response.ClearContent(); Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "BloombergDaily.csv")); Response.ContentType = "application/text"; GridView1.AllowPaging = false; GridView1.DataBind(); StringBuilder strbldr = new StringBuilder(); for (int i = 0; i &lt; GridView1.Columns.Count; i++) { strbldr.Append(GridView1.Columns[i].HeaderText + ','); } strbldr.Append("\n"); for (int j = 0; j &lt; GridView1.Rows.Count; j++) { for (int k = 0; k &lt; GridView1.Columns.Count; k++) { strbldr.Append(GridView1.Rows[j].Cells[k].Text + ','); } strbldr.Append("\n"); } Response.Write(strbldr.ToString()); Response.End(); } } </code></pre> <p>Here's what I have in the aspx file:</p> <pre><code>&lt;form id="form1" runat="server" action="/"&gt; &lt;div id="donotadd" class="tableWrapper"&gt; &lt;div id="tabs1"&gt; &lt;p&gt; &lt;div id="tabs-1" &gt; &lt;div id="DoNotAddListMacro" class="dataTable table_Center"&gt; &lt;umbraco:Macro ID="Macro1" Alias="DoNotAddListControl" runat="server"&gt;&lt;/umbraco:Macro&gt; &lt;/div&gt; &lt;/div&gt; &lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload