如何解决此错误: - 创建控件时出错 - gridview1。服务器标签格式不正确 [英] How do I solve this error :- error creating control - gridview1. The server tag is not well formed

查看:112
本文介绍了如何解决此错误: - 创建控件时出错 - gridview1。服务器标签格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想让我的gridview可编辑,这将填充数据库中的数据。当我的程序启动时,它将连接到数据库并使用数据填充gridview。现在我想编辑其中的数据。我不知道我在做什么错误,因为我在visual studio ERROR的设计视图中遇到此错误: - 创建控件时出错 - GridView1。服务器标签格式不正确。



查看标签并告诉我我在哪里犯错误。



我尝试过:



.aspx: -



 <%@     Page    标题  =    语言  =  C#    MasterPageFile   = 〜/ AdminHome / AdminMainPage.master    AutoEventWireup   =  true    CodeFile   =  questions.aspx.cs   继承  =  AdminHome_questions   %>  

< asp:Content ID = Content1 ContentPlaceHolderID = head Runat = 服务器 >
< / asp:Content >
< asp:内容 ID = Content2 ContentPlaceHolderID = ContentPlaceHolder1 Runat = 服务器 >

< asp:GridView ID = GridView1 宽度 = 100% < span class =code-attribute> runat = server AutoGenerateColumns = false

AllowPaging = true PageSize = 10 字体名称 = Arial

字体大小 = 11pt AlternatingRowStyle-BackColor = #C2D69B

HeaderStyle-BackColor = 绿色 OnPageIndexChanging = OnPaging >
< >
< asp:TemplateField ControlStyle-Width = 100% HeaderText = 问题 >


< ItemTemplate >


< asp:表 runat = server 宽度 = 100% >

< asp:TableRow < span class =code-attribute>
width = 100% >
< asp:TableCell >
<% #Eval( 描述%> < / asp:TableCell >
< ; / asp:TableRow >
< asp:TableRow 宽度 = 100% >
< asp:TableCell >
<% #Eval( 问题%> < / asp:TableCell >
< / asp:TableRow >
< asp:TableRow >
< asp:TableCell >
<% #Eval( Option1)< span class =code-pagedirective>%> < / asp:TableCell >
< asp:TableCell > ;
<% #Eval( Option2%> < / asp:TableCell >
< / asp:TableRow >
< asp:TableRow width = 100% >
< asp:TableCell >
<% #Eval( Option3%> < / asp:TableCell >
< asp:TableCell >
<% #Eval( Option4%> < / as p:TableCell >
< / asp:TableRow >
< asp:TableRow width = 100% >
< asp:TableCell >
< span class =code-pagedirective><% #Eval( CorrectAns%> < / asp:TableCell >
< / asp:TableRow >
< asp:TableRow width = 100% >
< asp:TableCell >
<% #Eval( 说明%> < / asp:TableCell >
&l t; / asp:TableRow >
< / asp:表 >


< / ItemTemplate >
< EditItemTemplate > ;
< asp:表 runat = server 宽度 = 100% >

< asp:TableRow width = 100% >
< asp:TableCell >
< asp:TextBox runat = 服务器 text = <% #Eval( 描述%> > < / asp:TextBox > < / asp:TableCell >
< / asp:TableRow >
< asp:TableRow width = 100 % >
< asp:TableCell >
< asp:TextBox runat = server text = <% #Eval( 问题 %> > < / asp:TextBox > < / asp:TableCell >
< / asp:TableRow >
< asp :TableRow >
< asp:TableCell >
< asp:TextBox runat = server text = <% #Eval( 问题%> > < / 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 = < span class =code-pagedirective><% #Eval( Option4%>
> < ; / asp:TextBox > < ; / asp:TableCell >
< / asp:TableRow >
< asp:TableRow width = 100% >
< asp:TableCell >
< < span class =code-leadattribute> asp:TextBox
runat = server text = <%# Eval( CorrectAns%> > < span class =code-keyword>< / asp:TextBox > < span class =code-keyword>< / asp:TableCell >
< / asp:TableRow >
< asp:TableRow width = 100% >
< asp: TableCell >
< asp:TextBox runat = server text = < span class =code-pagedirective><% #Eval( 说明%> > < ; / asp:TextBox > < ; / asp:TableCell >
< / asp:TableRow >
< / asp:Table >
< / EditItemTemplate >
< / asp:TemplateField >


< asp:TemplateField ControlStyle-Width = 100% >


< HeaderTemplate >
部分
&l t; asp:DropDownList runat = server OnSelectedIndexChanged = SectionChanged AutoPostBack = true

< span class =code-attribute> AppendDataBoundItems = true >
< asp:ListItem 文字 = ALL = ALL > < / asp:ListItem >
< asp:ListItem 文本 = 前10名 = 10 > < / asp:ListItem >

< / asp:DropDownList >
< / HeaderTemplate >
< ItemTemplate >
<% #Eval( SectionName%>
< / ItemTemplate >
< EditItemTemplate >
< asp: TextBox ID = txtPageDesc runat = 服务器 TextMode = MultiLine = < span class =code-keyword> 10 =\"50\"



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

</Columns>
</asp:GridView>

</asp:Content>

解决方案

< blockquote>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.


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.


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:-

<%@ 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>

解决方案

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.


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.


这篇关于如何解决此错误: - 创建控件时出错 - gridview1。服务器标签格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆