How to use dynamic grammar in c #?

I want to bind a data source to a GridView, but it does not work because the data source is dynamic, who can give me a hand? Thanks!

/ **** 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> 

Can't find ffid and name, why?

+4
source share
1 answer

Maybe if you added an element to dynamic

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


Or IDictionary<string, object> . ( ExpandoObject implements this)

 <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <%# ((IDictionary<string, object>)Container.DataItem)["FFID"] %> </ItemTemplate> </asp:Repeater> 
+5
source

Source: https://habr.com/ru/post/1412745/


All Articles