Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I'm just trying to make my gridview editable, which will be filled with data from the database. When my program starts, it will connect to the database and fill the gridview with data. Now i want to edit the data in it. I don't know what mistake I am doing due to which I am get this error in design view of visual studio ERROR:- Error creating control - GridView1. The server tag is not well formed.

Have a look at the tag and show me where I am making mistake.

What I have tried:

.aspx:-

ASP.NET
<%@ Page Title="" Language="C#" MasterPageFile="~/AdminHome/AdminMainPage.master" AutoEventWireup="true" CodeFile="questions.aspx.cs" Inherits="AdminHome_questions" %>

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

    <asp:GridView ID="GridView1" Width="100%" runat="server" AutoGenerateColumns = "false"
AllowPaging = "true" PageSize = "10"  Font-Names = "Arial"
Font-Size = "11pt" AlternatingRowStyle-BackColor = "#C2D69B" 
HeaderStyle-BackColor = "green"  OnPageIndexChanging = "OnPaging">
<Columns>
    <asp:TemplateField ControlStyle-Width="100%" HeaderText="Questions">
        

        <ItemTemplate>
            

            <asp:Table runat="server" Width="100%">
               
                <asp:TableRow width="100%">
                    <asp:TableCell>
                        <%# Eval("Description") %></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow width="100%">
                    <asp:TableCell>
                        <%# Eval("Question") %></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow >
                    <asp:TableCell>
                        <%# Eval("Option1") %></asp:TableCell>
                    <asp:TableCell>
                        <%# Eval("Option2") %></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow width="100%">
                    <asp:TableCell>
                        <%# Eval("Option3") %></asp:TableCell>
                    <asp:TableCell>
                        <%# Eval("Option4") %></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow width="100%">
                    <asp:TableCell>
                        <%# Eval("CorrectAns") %></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow width="100%">
                    <asp:TableCell>
                        <%# Eval("Explanation") %></asp:TableCell>
                </asp:TableRow>
            </asp:Table>
                    

        </ItemTemplate>
        <EditItemTemplate>
            <asp:Table runat="server" Width="100%">
               
                <asp:TableRow width="100%">
                    <asp:TableCell>
                        <asp:TextBox runat="server" text="<%# Eval("Description")%>"></asp:TextBox> </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow width="100%">
                    <asp:TableCell>
                        <asp:TextBox runat="server" text="<%# Eval("Question") %>"></asp:TextBox></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow >
                    <asp:TableCell>
                        <asp:TextBox runat="server" text="<%# Eval("Question") %>"></asp:TextBox></asp:TableCell>
                    <asp:TableCell>
                        <asp:TextBox runat="server" text="<%# Eval("Option2") %>"></asp:TextBox></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow width="100%">
                    <asp:TableCell>
                        <asp:TextBox runat="server" text="<%# Eval("Option3") %>"></asp:TextBox></asp:TableCell>
                    <asp:TableCell>
                        <asp:TextBox runat="server" text="<%# Eval("Option4") %>"></asp:TextBox></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow width="100%">
                    <asp:TableCell>
                        <asp:TextBox runat="server" text="<%# Eval("CorrectAns") %>"></asp:TextBox></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow width="100%">
                    <asp:TableCell>
                        <asp:TextBox runat="server" text="<%# Eval("Explanation") %>"></asp:TextBox></asp:TableCell>
                </asp:TableRow>
            </asp:Table>
        </EditItemTemplate>
    </asp:TemplateField>


<asp:TemplateField ControlStyle-Width="100%">
        

        <HeaderTemplate>
Sections 
<asp:DropDownList runat="server" OnSelectedIndexChanged = "SectionChanged" AutoPostBack = "true"
            AppendDataBoundItems = "true">
                 <asp:ListItem Text = "ALL" Value = "ALL"></asp:ListItem>
            <asp:ListItem Text = "Top 10" Value = "10"></asp:ListItem>

             </asp:DropDownList>
</HeaderTemplate>
<ItemTemplate>
<%# Eval("SectionName") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtPageDesc" runat="Server" TextMode="MultiLine" Rows="10" Columns="50"

                                Text='<%# Eval("SectionName") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>

    </Columns>
        </asp:GridView>

</asp:Content>
Posted
Updated 8-Aug-21 20:41pm
Comments
Herman<T>.Instance 22-Apr-16 3:41am    
Set each itemtemplate in comment and see if the gridview stops giving exceptions. If that does, add per itemtemplate back again. So you can find out your problem
CHill60 22-Apr-16 3:59am    
If you have a look at the HeaderTemplate at the bottom of the code you posted there is a word "Sections" which doesn't appear to be valid
Member 12170781 22-Apr-16 5:50am    
the error is same after removing it
CHill60 22-Apr-16 6:25am    
Well I can tell you that the error is in the <EditItemTemplate> section but I haven't worked out why yet

As digimanus said in comments, you need to narrow down where the problem is. You can do this pretty fast. Just remove sections until you find the one. Then fix it. Pretty simple.
 
Share this answer
 
A silly mistake I did in the code due to which it is showing error.

While binding data to textbox I wrote text="<%# Eval("Description")%>" instead of writing text='<%# Eval("Description")%>'

Instead of "" write ''.

Same for all TextBox.
 
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