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"><%@ Page Title="" Language="C#" MasterPageFile="~/Master Admin.master" AutoEventWireup="true" CodeFile="coder_view.aspx.cs" Inherits="coder_view" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link rel="stylesheet" type="text/css" href="css/default.css"/>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div >
<asp:GridView ID="grdcoderview" runat="server" AutoGenerateColumns="false"
AllowPaging="true" ShowFooter="True" rowstyle-cssclass="rowHover">
<Columns>
<asp:TemplateField HeaderText="CodersID" HeaderStyle-BackColor="#373C40" >
<ItemTemplate>
<asp:Label ID="lblcoder1" runat="server" Text='<%#bind("userid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="First Name" HeaderStyle-BackColor="#373C40">
<ItemTemplate>
<asp:Label ID="lblcoder2" runat="server" Text='<%#bind("firstname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name" HeaderStyle-BackColor="#373C40">
<ItemTemplate>
<asp:Label ID="lblcoder3" runat="server" Text='<%#bind("lastname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email ID" HeaderStyle-BackColor="#373C40">
<ItemTemplate>
<asp:Label ID="lblcoder4" runat="server" Text='<%#bind("emailid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Username" HeaderStyle-BackColor="#373C40">
<ItemTemplate>
<asp:Label ID="lblcoder5" runat="server" Text='<%#bind("username") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Password" HeaderStyle-BackColor="#373C40">
<ItemTemplate>
<asp:Label ID="lblcoder6" runat="server" Text='<%#bind("password") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Image" HeaderStyle-BackColor="#373C40">
<ItemTemplate>
<asp:Image ID="imagecoder" runat="server" ImageUrl='<%#bind("image") %>' Width="50px" Height="50px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Phone No" HeaderStyle-BackColor="#373C40">
<ItemTemplate>
<asp:Label ID="lblcoder8" runat="server" Text='<%#bind("phoneno") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address" HeaderStyle-BackColor="#373C40">
<ItemTemplate>
<asp:Label ID="lblcoder9" runat="server" Text='<%#bind("address") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Qualification" HeaderStyle-BackColor="#373C40">
<ItemTemplate>
<asp:Label ID="lblcoder10" runat="server" Text='<%#bind("qualification") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Functional Area" HeaderStyle-BackColor="#373C40">
<ItemTemplate>
<asp:Label ID="lblcoder11" runat="server" Text='<%#bind("functionalarea") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Organisation name" HeaderStyle-BackColor="#373C40">
<ItemTemplate>
<asp:Label ID="lblcoder12" runat="server" Text='<%#bind("organisationname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Toatal Experience" HeaderStyle-BackColor="#373C40">
<ItemTemplate>
<asp:Label ID="lblcoder13" runat="server" Text='<%#bind("totalexperience") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Resume" HeaderStyle-BackColor="#373C40">
<ItemTemplate>
<asp:Label ID="lblcoder14" runat="server" Text='<%#bind("resume") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ImageButton ID="ImageButton1" runat="server"
onclick="ImageButton1_Click" Height="27px" ImageUrl="~/images/logo.png"
Width="36px" />
</div>
</asp:Content></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();
}
}