4

我想将数据源绑定到GridView,但它不起作用,因为数据源是动态的,谁能帮我一把?谢谢!

/ * *** c#** * ** * * /

List<dynamic> dyList = new List<dynamic>();
dynamic info1 = new ExpandoObject();
info1.FFID = 1;
info1.Name = "Bill1";

dynamic info2 = new ExpandoObject();
info2.FFID = 2;
info2.Name = "Bill2";

dyList.Add(info1);
dyList.Add(info2);

Repeater1.DataSource = dyList;
Repeater1.DataBind();

/ * *** aspx * ** * *** /

<asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <%# Eval("FFID") %> <%# Eval("Name") %>
        </ItemTemplate>
    </asp:Repeater>

找不到 FFid 和名称,为什么?

4

1 回答 1

5

也许如果您将项目投射到dynamic

<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
         <%# ((dynamic)Container.DataItem).FFID %>
     </ItemTemplate>
</asp:Repeater>


或到IDictionary<string, object>. (ExpandoObject实现)

<asp:Repeater ID="Repeater1" runat="server">
     <ItemTemplate>
          <%# ((IDictionary<string, object>)Container.DataItem)["FFID"] %>
     </ItemTemplate>
</asp:Repeater>
于 2012-05-16T09:29:34.340 回答