错误: “元素'BoundField'不是已知元素如果网站中存在编译错误,或者缺少web.config文件,则会发生这种情况。”为什么这个错误?以及如何解决?
标记:
<asp:ScriptManager ID="ScriptManager2" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<asp:GridView ID="GridView1" CssClass="GridGis" runat="server"
AutoGenerateColumns="False" PageSize="5" OnPageIndexChanging="GridView1_PageIndexChanging"
AllowPaging="True">
<columns>
<asp:BoundField DataField="nome" HeaderText="Nome" />
</columns>
</asp:GridView>
</asp:UpdatePanel>
答案 0 :(得分:1)
您需要将GridView
放在ContentTemplate
:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GridView1" CssClass="GridGis"
runat="server" AutoGenerateColumns="False" PageSize="5"
OnPageIndexChanging="GridView1_PageIndexChanging" AllowPaging="True">
<Columns>
<asp:BoundField DataField="nome" HeaderText="Nome" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
编辑:以下是我测试代码的方法:
在标记中我添加了一个HTML输入,它的内容在部分回发后不会改变。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="PostbackTest.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="upd" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" CssClass="GridGis"
runat="server" AutoGenerateColumns="False" PageSize="3"
OnPageIndexChanging="GridView1_PageIndexChanging" AllowPaging="True">
<Columns>
<asp:BoundField DataField="nome" HeaderText="Nome" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<input type="text" id="input" />
</div>
</form>
</body>
</html>
在代码中,我在Page_Load上使用虚拟数据填充了gridview。这是代码:
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
namespace PostbackTest
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = new List<MyClass>(){new MyClass{ID=1, NOME="ad"},
new MyClass{ID=2, NOME="sdf"},
new MyClass{ID=3, NOME="fgdf"},
new MyClass{ID=4, NOME="fgd"},
new MyClass{ID=5, NOME="aghfgd"},
new MyClass{ID=6, NOME="jhkj"}};
GridView1.DataBind();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
}
private class MyClass
{
public int ID { get; set; }
public string NOME { get; set; }
}
}
}