我已經聲明瞭一個類,但是當我嘗試訪問它的成員時,出現以下錯誤:
DataBinding:'reapTest.Toop'不包含名爲'Rang'的屬性。爲什麼DataBinding無法找到存在的屬性?
WebForm1.aspx.cs中:
namespace reapTest {
public class Toop {
public string Rang;
public int Gheymat;
}
public static class MyData {
public static Toop[] TP = new Toop[] { new Toop() { Rang = "Ghermez", Gheymat = 100 }, new Toop() { Rang = "Yellow", Gheymat = 44 } };
public static Toop[] RT() {
return TP;
}
}
public partial class WebForm1 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
}
}
WebForm1.aspx的:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="reapTest.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:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1">
<ItemTemplate>
<%#Eval("Rang")%>
</ItemTemplate>
</asp:Repeater>
<asp:ObjectDataSource runat="server" ID="ObjectDataSource1" SelectMethod="RT" TypeName="reapTest.MyData"></asp:ObjectDataSource>
</div>
</form>
</body>
</html>
我相信這是因爲它正在尋找名爲Rang的* literal *屬性。你有一個叫做Rang的字段,但這不同於一個屬性。只是一個想法。 – 2013-02-15 19:02:26
@David,這個想法會讓人很好的回答:) – 2013-02-15 19:03:16
@DavidW奇妙的是,當我第一次運行網站時,我可以使它工作。 – 2013-02-15 19:04:42