locked
Label is not recognized and gives me ParserError. Why? RRS feed

  • Question

  • User766850287 posted

    In my template field I am getting the warning: "'Label' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing."

    The web.config file is not missing, and when I try searching for a solution to this problem online, I only see people who writing that it should be ignored. The problem is that this error is giving me a ParserError when I try to load the page: "System.Web.UI.WebControls.TemplateField does not have a public property named Label".

    How do I solve this?

    <%@ Page Title="" Language="C#" MasterPageFile="~/index.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="cmsSystem.WebForm1" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
        <style type="text/css">
            .auto-style1 {
                margin-right: 25px;
            }
        </style>
    </asp:Content>
    <asp:Content ID="Content3" ContentPlaceHolderID="header" runat="server">
    
        <asp:GridView ID="gridView1" runat="server" CssClass="auto-style1" Width="731px" BorderWidth="0" AutoGenerateColumns="false" DataKeyNames="HeaderID">
            <Columns>
                <asp:TemplateField HeaderText="LogoText">
                    <asp:Label ID="lbl1" Text='<%#eval("LogoText")%>' runat="server" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="">
                    <asp:Label ID="lbl2" Text='<%# eval("Link1") %>' runat="server" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="">
                    <asp:Label ID="lbl3" Text='<%# eval("Link2") %>' runat="server" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="">
                    <asp:Label ID="lbl4" Text='<%# eval("Link3") %>' runat="server" />
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    </asp:Content>



    Sunday, March 29, 2020 12:15 PM

All replies

  • User-258456925 posted

    There are couple of things to check.

    • change eval to Eval as <asp:Label ID="lbl1" Text='<%# Eval("LogoText")%>' runat="server" />
    • do clean build solution

    If that doesn't solve the issue, try this demo insert update delete gridview records in asp.net here.

    Sunday, March 29, 2020 3:29 PM
  • User-1330468790 posted

    Hi McQvist,

     

    Actually, your problem is pretty clear as you put the label under a wrong tag. I can see that you are using the tag <asp:TemplateField> which should contains some template tags first e.g. <ItemTemplate>, <AlternatingItemTemplate>, <InsertItemTemplate>, <EditItemTemplate>, <HeaderTemplate>, <FooterTemplate>. Then you will be able to add any server control under these tags.

    What's more, you really have to correct the spelling of 'eval' to 'Eval' since it is a method of the c# code which means the first letter should be always in upper case.

      

    Solution:

    Rewrite the markup for the GridView control => Add <ItemTemplate> under the <asp:TemplateField/> tag.

    <asp:GridView ID="gridView1" runat="server" CssClass="auto-style1" Width="731px" BorderWidth="0" AutoGenerateColumns="false" DataKeyNames="HeaderID">
            <Columns>
                <asp:TemplateField HeaderText="LogoText">
                    <ItemTemplate>
                         <asp:Label ID="lbl1" Text='<%# Eval("LogoText")%>' runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="">
                    <ItemTemplate>
                        <asp:Label ID="lbl2" Text='<%# Eval("Link1") %>' runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="">
                    <ItemTemplate>
                        <asp:Label ID="lbl3" Text='<%# Eval("Link2") %>' runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="">
                    <ItemTemplate>
                        <asp:Label ID="lbl4" Text='<%# Eval("Link3") %>' runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

     

    More information about the declarative syntaxv of the GridView control, you can refer to below link:

    https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.gridview?view=netframework-4.8#declarative_syntax

      

    Hope this can help you.

    Best regards,

    Sean

    Monday, March 30, 2020 1:56 AM