error "Control 'GridView' must be placed inside a form tag with runat=server"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ramuksasi
    New Member
    • Oct 2010
    • 4

    error "Control 'GridView' must be placed inside a form tag with runat=server"

    Hi,
    I've an asp.net .ascx form and a gridview on that form.I've placed that form on an .aspx. Now while I'm trying to import data from gridview to excel it is showing the error "Control 'GridView' must be placed inside a form tag with runat=server"

    see my code:

    Code:
     <form action="readdata.aspx" runat="server">
            <table>
                <tr>
                    <td style="width: 100px">
                        <asp:Label ID="lblSearchBy" runat="server" Text="Search by:"></asp:Label></td>
                    <td style="width: 100px">
                        <asp:DropDownList ID="cmbSheets" runat="server" DataSourceID="SqlDataSource1" DataTextField="ISSUEID" DataValueField="ISSUEID">
                            <asp:ListItem Value="0">Students</asp:ListItem>
                            <asp:ListItem Value="1">Mathematics</asp:ListItem>
                            <asp:ListItem Value="2">Geography</asp:ListItem>
                        </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MCWEBConnectionString2 %>"
                            SelectCommand="SELECT [ISSUEID] FROM [MCISSUES]"></asp:SqlDataSource>
                    </td>
                        
                    <td>
                        <asp:Button ID="btnSearch" runat="server" Text="Search" /></td>
                </tr>
            </table>
            <br />
         <asp:GridView ID="dgResults" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
                <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" />
            </asp:GridView>
            <asp:Button ID="btnToExcelByResponse" runat="server" Style="z-index: 100; left: 92px;
                position: absolute; top: 393px" Text="Export to Excel using Response Object" />
                </form>
    Last edited by MMcCarthy; Oct 17 '10, 09:29 PM. Reason: added code tags
Working...