我收到以下错误: 在所选数据源上找不到名为“PageId”的字段或属性。
这将使得如果PageId不在对象中 - 但它确实如此。这是aspx:
<asp:UpdatePanel EnableViewState="true" UpdateMode="Conditional" ID="pnlPagesDislay" runat="server">
<ContentTemplate>
<asp:GridView ID="grdMediaFilesetPages" AllowSorting="false" AllowPaging="false" runat="server" AutoGenerateColumns="False" OnRowCommand="grdMediaFilesetPages_RowCommand" CellPadding="2" ForeColor="#333333" GridLines="None" Width="1000px">
<FooterStyle BackColor="#49a4d4" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="PageId" HeaderText="Page ID" InsertVisible="False" ReadOnly="True">
<HeaderStyle HorizontalAlign="Left" Wrap="true" />
</asp:BoundField>
<asp:BoundField DataField="LayoutId" HeaderText="Layout" InsertVisible="False" ReadOnly="True">
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Images" HeaderText="Images" InsertVisible="False" ReadOnly="True">
<HeaderStyle HorizontalAlign="Left" Wrap="true" />
</asp:BoundField>
<asp:TemplateField HeaderText="Actions" AccessibleHeaderText="Actions" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Right">
<ItemTemplate><span style="white-space:nowrap">
<a href="<%# DataBinder.Eval(Container.DataItem, "EditLink") %>">Edit</a> |
<asp:LinkButton ID='RemoveLinkBtn' Text='Remove' CommandName='RemoveLanguageAttr' CommandArgument='<%# DataBinder.Eval(Container.DataItem, "LangAttrId") %>' runat='server' />
</span>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#49a4d4" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#49a4d4" Font-Bold="True" VerticalAlign="Bottom" ForeColor="White" Wrap="true" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
这是背后的代码:
_mediaFilesetPages = new List<MediaFilesetPage> {new MediaFilesetPage
{
EditLink = "",
ID = "",
ImageFile = "testing.png",
LayoutId = "1",
PageId = "0001",
RemoveLink = ""
}};
grdMediaFilesetPages.DataSource = _mediaFilesetPages;
grdMediaFilesetPages.DataBind();
这是MediaFilesetPage对象:
internal class MediaFilesetPage
{
public string ID;
public string PageId;
public string LayoutId;
public string ImageFile;
public string EditLink;
public string RemoveLink;
}
任何人都知道问题是什么?
答案 0 :(得分:3)
将您的字段设为公共属性:
internal class MediaFilesetPage
{
public string ID {get; set; }
public string PageId {get; set; }
public string LayoutId {get; set; }
public string ImageFile {get; set; }
public string EditLink {get; set; }
public string RemoveLink {get; set; }
}