在GridView的DataBinding()時出現以下錯誤。 儘管「siteName」字段被定義爲結構「StructSelectedSiteList」的一部分,但ASP.net gridview定義中的DataBinder(...)無法識別該字段。所有的領域和結構被定義爲公共的。DataBinding:'UserControls.SiteDetails + StructSelectedSiteList'不包含名稱爲'siteName'的屬性
我已經提到以前的帖子,但它沒有幫助。 DataBinding does not contain a property
欣賞您的回覆。謝謝!
這是代碼。 StructSelectedSiteList - 填充值的結構。這是數據源。
[Serializable]
public struct StructSelectedSiteList
{
public string siteName;
public int taskId;
};
在下面的代碼中,填充結構。
var lstSites = new List<StructSelectedSiteList>();
LOOP1:
// populate the struct for selected sites
StructSelectedSiteList structSelectedSiteList;
structSelectedSiteList.siteName = lblSiteName.Text;
structSelectedSiteList.taskId = taskId;
lstSites.Add(structSelectedSiteList);
現在gridview綁定了填充結構。
gvSelectedSites.DataSource = lstSites;
gvSelectedSites.DataBind(); <<----- Error occurs here
的ASP.net GridView的定義是 -
<asp:GridView ID="gvSelectedSites" runat="server" AutoGenerateColumns="False" AllowSorting="True"
CellPadding="4" EmptyDataText="There are no data records to display." Font-Names="Segoe UI"
Width="605px" ForeColor="#333333" GridLines="None" RowStyle-HorizontalAlign="Center"
EmptyDataRowStyle-Font-Bold="true" EmptyDataRowStyle-ForeColor="Red" OnRowDataBound="gvSelectedSites_OnRowDataBound">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="siteName">
<ItemTemplate>
<asp:Label ID="lblSiteName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "siteName")%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Task" Visible="false">
<ItemTemplate>
<asp:Label ID="lblTaskId" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "taskId")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
我發現我沒有訪問'siteName'屬性。因此,我試圖首先將該字段轉換爲屬性。 –