Getting error in content page(while converting gridview data

Mar 26 2014 8:35 AM
i have created a master page..(in master page form tag and runat=server is there)
in content page, i'm trying to convert gridview data to pdf...
while converting, it shows error
error:
Control 'ContentPlaceHolder1_grdcoderview' of type 'GridView' must be placed inside a form tag with runat=server.
soure page:
<pre lang="xml">&lt;%@ Page Title=&quot;&quot; Language=&quot;C#&quot; MasterPageFile=&quot;~/Master Admin.master&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;coder_view.aspx.cs&quot; Inherits=&quot;coder_view&quot; %&gt;
&lt;asp:Content ID=&quot;Content1&quot; ContentPlaceHolderID=&quot;head&quot; Runat=&quot;Server&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;css/default.css&quot;/&gt;
&lt;/asp:Content&gt;
&lt;asp:Content ID=&quot;Content2&quot; ContentPlaceHolderID=&quot;ContentPlaceHolder1&quot; Runat=&quot;Server&quot;&gt;
&lt;div &gt;
&lt;asp:GridView ID=&quot;grdcoderview&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;false&quot;
AllowPaging=&quot;true&quot; ShowFooter=&quot;True&quot; rowstyle-cssclass=&quot;rowHover&quot;&gt;
&lt;Columns&gt;
&lt;asp:TemplateField HeaderText=&quot;CodersID&quot; HeaderStyle-BackColor=&quot;#373C40&quot; &gt;
&lt;ItemTemplate&gt;
&lt;asp:Label ID=&quot;lblcoder1&quot; runat=&quot;server&quot; Text='&lt;%#bind(&quot;userid&quot;) %&gt;'&gt;&lt;/asp:Label&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;asp:TemplateField HeaderText=&quot;First Name&quot; HeaderStyle-BackColor=&quot;#373C40&quot;&gt;
&lt;ItemTemplate&gt;
&lt;asp:Label ID=&quot;lblcoder2&quot; runat=&quot;server&quot; Text='&lt;%#bind(&quot;firstname&quot;) %&gt;'&gt;&lt;/asp:Label&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;asp:TemplateField HeaderText=&quot;Last Name&quot; HeaderStyle-BackColor=&quot;#373C40&quot;&gt;
&lt;ItemTemplate&gt;
&lt;asp:Label ID=&quot;lblcoder3&quot; runat=&quot;server&quot; Text='&lt;%#bind(&quot;lastname&quot;) %&gt;'&gt;&lt;/asp:Label&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;asp:TemplateField HeaderText=&quot;Email ID&quot; HeaderStyle-BackColor=&quot;#373C40&quot;&gt;
&lt;ItemTemplate&gt;
&lt;asp:Label ID=&quot;lblcoder4&quot; runat=&quot;server&quot; Text='&lt;%#bind(&quot;emailid&quot;) %&gt;'&gt;&lt;/asp:Label&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;asp:TemplateField HeaderText=&quot;Username&quot; HeaderStyle-BackColor=&quot;#373C40&quot;&gt;
&lt;ItemTemplate&gt;
&lt;asp:Label ID=&quot;lblcoder5&quot; runat=&quot;server&quot; Text='&lt;%#bind(&quot;username&quot;) %&gt;'&gt;&lt;/asp:Label&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;asp:TemplateField HeaderText=&quot;Password&quot; HeaderStyle-BackColor=&quot;#373C40&quot;&gt;
&lt;ItemTemplate&gt;
&lt;asp:Label ID=&quot;lblcoder6&quot; runat=&quot;server&quot; Text='&lt;%#bind(&quot;password&quot;) %&gt;'&gt;&lt;/asp:Label&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;asp:TemplateField HeaderText=&quot;Image&quot; HeaderStyle-BackColor=&quot;#373C40&quot;&gt;
&lt;ItemTemplate&gt;
&lt;asp:Image ID=&quot;imagecoder&quot; runat=&quot;server&quot; ImageUrl='&lt;%#bind(&quot;image&quot;) %&gt;' Width=&quot;50px&quot; Height=&quot;50px&quot; /&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;asp:TemplateField HeaderText=&quot;Phone No&quot; HeaderStyle-BackColor=&quot;#373C40&quot;&gt;
&lt;ItemTemplate&gt;
&lt;asp:Label ID=&quot;lblcoder8&quot; runat=&quot;server&quot; Text='&lt;%#bind(&quot;phoneno&quot;) %&gt;'&gt;&lt;/asp:Label&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;asp:TemplateField HeaderText=&quot;Address&quot; HeaderStyle-BackColor=&quot;#373C40&quot;&gt;
&lt;ItemTemplate&gt;
&lt;asp:Label ID=&quot;lblcoder9&quot; runat=&quot;server&quot; Text='&lt;%#bind(&quot;address&quot;) %&gt;'&gt;&lt;/asp:Label&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;asp:TemplateField HeaderText=&quot;Qualification&quot; HeaderStyle-BackColor=&quot;#373C40&quot;&gt;
&lt;ItemTemplate&gt;
&lt;asp:Label ID=&quot;lblcoder10&quot; runat=&quot;server&quot; Text='&lt;%#bind(&quot;qualification&quot;) %&gt;'&gt;&lt;/asp:Label&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;asp:TemplateField HeaderText=&quot;Functional Area&quot; HeaderStyle-BackColor=&quot;#373C40&quot;&gt;
&lt;ItemTemplate&gt;
&lt;asp:Label ID=&quot;lblcoder11&quot; runat=&quot;server&quot; Text='&lt;%#bind(&quot;functionalarea&quot;) %&gt;'&gt;&lt;/asp:Label&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;asp:TemplateField HeaderText=&quot;Organisation name&quot; HeaderStyle-BackColor=&quot;#373C40&quot;&gt;
&lt;ItemTemplate&gt;
&lt;asp:Label ID=&quot;lblcoder12&quot; runat=&quot;server&quot; Text='&lt;%#bind(&quot;organisationname&quot;) %&gt;'&gt;&lt;/asp:Label&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;asp:TemplateField HeaderText=&quot;Toatal Experience&quot; HeaderStyle-BackColor=&quot;#373C40&quot;&gt;
&lt;ItemTemplate&gt;
&lt;asp:Label ID=&quot;lblcoder13&quot; runat=&quot;server&quot; Text='&lt;%#bind(&quot;totalexperience&quot;) %&gt;'&gt;&lt;/asp:Label&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;asp:TemplateField HeaderText=&quot;Resume&quot; HeaderStyle-BackColor=&quot;#373C40&quot;&gt;
&lt;ItemTemplate&gt;
&lt;asp:Label ID=&quot;lblcoder14&quot; runat=&quot;server&quot; Text='&lt;%#bind(&quot;resume&quot;) %&gt;'&gt;&lt;/asp:Label&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;/Columns&gt;
&lt;/asp:GridView&gt;
&lt;asp:ImageButton ID=&quot;ImageButton1&quot; runat=&quot;server&quot;
onclick=&quot;ImageButton1_Click&quot; Height=&quot;27px&quot; ImageUrl=&quot;~/images/logo.png&quot;
Width=&quot;36px&quot; /&gt;
&lt;/div&gt;
&lt;/asp:Content&gt;</pre>
aspx.cs page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
using System.IO;
public partial class coder_view : System.Web.UI.Page
{
Class1 obj = new Class1();
protected void Page_Load(object sender, EventArgs e)
{
grdcoderview.DataSource = obj.displaycoder();
grdcoderview.DataBind();
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
grdcoderview.AllowPaging = false;
grdcoderview.DataBind();
grdcoderview.RenderControl(hw);
grdcoderview.HeaderRow.Style.Add("width", "15%");
grdcoderview.HeaderRow.Style.Add("font-size", "10px");
grdcoderview.Style.Add("text-decoration", "none");
grdcoderview.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
grdcoderview.Style.Add("font-size", "8px");
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
}

Answers (1)