Click here to Skip to main content
15,880,364 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ERROR:Control 'ContentPlaceHolder1_gridreport' of type 'GridView' must be placed inside a form tag with runat=server.

Plz help me to get answer

C#
protected void btnexport_Click(object sender, EventArgs e)
  {

      string attachment = "attachment; filename=Emp.xls";
      Response.ClearContent();
      Response.AddHeader("content-disposition", attachment);
      Response.ContentType = "application/ms-excel";
      StringWriter sw = new StringWriter();
      HtmlTextWriter htw = new HtmlTextWriter(sw);
      gridreport.RenderControl(htw);
      Response.Write(sw.ToString());
      Response.End();

  }

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
XML
<asp:Panel ID="Panel1" runat="server" Height="317px" ScrollBars="Both">

        <asp:GridView ID="gridreport" runat="server" BackColor="White"
            BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3"
            Height="294px" Width="418px">
            <FooterStyle BackColor="White" ForeColor="#000066" />
            <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
            <RowStyle ForeColor="#000066" />
            <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F1F1F1" />
            <SortedAscendingHeaderStyle BackColor="#007DBB" />
            <SortedDescendingCellStyle BackColor="#CAC9C9" />
            <SortedDescendingHeaderStyle BackColor="#00547E" />
        </asp:GridView>

    </asp:Panel>

</asp:Content>
Posted
Updated 22-Nov-14 2:26am
v4

1 solution

Add
C#
<form id="form1" runat="server"></form>
 
Share this answer
 
Comments
Member 11255166 22-Nov-14 8:44am    
i have added but getting the same error
Member 11255166 22-Nov-14 9:14am    
AM GETTING THIS ERROR

Server Error in '/MasterPage' Application.
A page can have only one server-side Form tag.
King Fisher 22-Nov-14 9:54am    
if you have For tag on you Master Page please remove that

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900