Reputation: 15
Error when using Update Panel with gridview:. "Element 'BoundField' 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." why this error? and how to solve?
Markup:
<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>
Upvotes: 1
Views: 1680
Reputation: 7943
You need to put the GridView
inside 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>
EDIT : Here's how I have tested your code:
In the markup I have added one HTML input, it's content will not changed after partial postback.
<%@ 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>
In the code I populated the gridview with dummy data on Page_Load. Here's the code:
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; }
}
}
}
Upvotes: 1