brdrok
asked on
Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
Hi,
I am getting the following error:
Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
below is the code:
protected void Page_Load(object sender, EventArgs e)
{
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWrit er hw = new System.Web.UI.HtmlTextWrit er(tw);
DataBridge.PrismPanc pp = new PrismPanc();
System.Data.DataTable dtExport = pp.GetTodaysData();
GridView1.DataSource = dtExport;
GridView1.DataBind();
Excel.Application oXl;
Excel._Workbook oWb;
Excel._Worksheet oSheet;
hw.WriteLine("<b><u><font size='5'>" +
"Report for the Fiscal year: </font></u></b>");
hw.WriteLine("<br>∓nbsp ;");
GridView1.HeaderStyle.Font .Bold = true;
GridView1.DataBind();
GridView1.RenderControl(hw ); //<-----generating the above error message
// Write the HTML back to the browser.
Response.ContentType = "application/vnd.ms-excel" ;
this.EnableViewState = false;
Response.Write(tw.ToString ());
Response.End();
I am getting the following error:
Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
below is the code:
protected void Page_Load(object sender, EventArgs e)
{
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWrit
DataBridge.PrismPanc pp = new PrismPanc();
System.Data.DataTable dtExport = pp.GetTodaysData();
GridView1.DataSource = dtExport;
GridView1.DataBind();
Excel.Application oXl;
Excel._Workbook oWb;
Excel._Worksheet oSheet;
hw.WriteLine("<b><u><font size='5'>" +
"Report for the Fiscal year: </font></u></b>");
hw.WriteLine("<br>∓nbsp
GridView1.HeaderStyle.Font
GridView1.DataBind();
GridView1.RenderControl(hw
// Write the HTML back to the browser.
Response.ContentType = "application/vnd.ms-excel"
this.EnableViewState = false;
Response.Write(tw.ToString
Response.End();
ASKER
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:GridView ID="GridView1" runat="server" Height="263px" Width="633px">
</asp:GridView>
</form>
</body>
</html>
The GridView is within the <form...> and </form> tags.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:GridView ID="GridView1" runat="server" Height="263px" Width="633px">
</asp:GridView>
</form>
</body>
</html>
The GridView is within the <form...> and </form> tags.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you're databinding gridview1 twice.
ASKER
I am not exactly sure what this whole enableEventValidation bit is all about but turning it to false seems to do the trick.
enableEventValidation ="false"
enableEventValidation ="false"
<form runat="server">
<asp:gridview>...
</form>