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


following code:-

XML
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <title> Print Reciept</title>
    <link href="ClassicGridView.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function checkAll(objRef) {
            var GridView = objRef.parentNode.parentNode.parentNode;
            var inputList = GridView.getElementsByTagName("input");
            for (var i = 0; i < inputList.length; i++) {
                var row = inputList[i].parentNode.parentNode;
                if (inputList[i].type == "checkbox" && objRef != inputList[i]) {
                    if (objRef.checked) {
                        inputList[i].checked = true;
                    }
                    else {
                        inputList[i].checked = false;
                    }
                }
            }
        }
    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <div style="margin-left:190px;">
        <h2>
            Print GridView Data As Bill Receipt
        </h2>
        <asp:Button ID="btnPrint" runat="server" CssClass="btn" Style="margin-bottom: 10px;"
            Text="Print Selected Record"  Width="174px" OnClick="btnPrint_Click" />
        <asp:GridView ID="Gridview1" GridLines="None" Width="40%" SkinID="GridviewSkin" AutoGenerateColumns="false"
            runat="server">
            <Columns>
                <asp:TemplateField>
                    <HeaderTemplate>
                        <asp:CheckBox ID="checkAll" runat="server" onclick="checkAll(this);" />
                    </HeaderTemplate>

                    <ItemTemplate>

                           <asp:CheckBox ID="ChkOne" runat="server"></asp:CheckBox>
                            <asp:HiddenField ID="hdnCHKOneID" Value='<%#Eval("fid") %>' runat="server" />

                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Fees Id">
                    <ItemTemplate>

                        <asp:Label ID="Label1" runat="server" Text='<%#Eval("fid") %>'></asp:Label>

                    </ItemTemplate>

                </asp:TemplateField>
                <asp:TemplateField HeaderText="Date">
                    <ItemTemplate>
                        <%#Eval("date") %>
                    </ItemTemplate>


                </asp:TemplateField>
                <asp:TemplateField HeaderText="Registration No.">
                    <ItemTemplate>
                        <%#Eval("regno") %>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Student Name">

                    <ItemTemplate>
                        <%#Eval("stuname") %>
                    </ItemTemplate>
                </asp:TemplateField>

                 <asp:TemplateField HeaderText="Course Name">

                    <ItemTemplate>
                        <%#Eval("cname") %>
                    </ItemTemplate>
                </asp:TemplateField>

                 <asp:TemplateField HeaderText="Fees">

                    <ItemTemplate>
                        <%#Eval("fees") %>
                    </ItemTemplate>
                </asp:TemplateField>

                 <asp:TemplateField HeaderText="Balance">

                    <ItemTemplate>
                        <%#Eval("balance") %>
                    </ItemTemplate>
                </asp:TemplateField>

            </Columns>
            <HeaderStyle CssClass="HeaderStyle" />
            <RowStyle CssClass="RowStyle" />
            <AlternatingRowStyle CssClass="AltRowStyle" />

        </asp:GridView>
    </div>

</asp:Content>
Posted
Comments
Bh@gyesh 14-Jul-14 3:20am    
Chceck your master page. It must contain <Form> tag. If not, put <form> tag.

1 solution

As your code says you are using master page and content page mechanism and you have shown the code of your content page.

Now, As this error :- " Control 'ContentPlaceHolder1_Gridview1' of type 'GridView' must be placed inside a form tag with runat=server. "

Says that gridview control should be placed inside the form tag i.e.

<form runat="server">
...
...
....
<asp:gridview runat="server">
.....
</asp:gridview>
....
...
...
</form>

If you are not using form tag in master page then just surround the gridview control (in the content page) with the form tag as shown above and your problem will be solved.
 
Share this answer
 
v4

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