【问题标题】:Populate drop down list with iEnumerable使用 iEnumerable 填充下拉列表
【发布时间】:2012-11-07 19:33:23
【问题描述】:

如何在 iEnumerable 参与者的中继器中填充下拉列表?

    Dim ac = pl.pages _
        .Where(Function(p) p.urlName = "2012Basketball" And p.organization.urlName = "CopleyHS") _
        .SelectMany(Function(p) p.actions) _
        .GroupBy(Function(s) s.eventId) _
        .[Select](Function(g) New With { _
          Key .EventId = g.Key, _
          Key .EventName = g.FirstOrDefault().event.name, _
          Key .Actions = g.[Select](Function(s) New With { _
            Key .ActionId = s.id, _
            Key .ActionName = s.name, _
            Key .Participants = s.event.participants.[Select](Function(k) New With { _
                Key .ParticipantName = k.name, _
                Key .ParticipantId = k.id _
            }) _
          }) _
       })

    rep_Events.DataSource = ac
    rep_Events.DataBind()

.aspx:

<asp:Repeater ID="rep_Events" runat="server">
    <ItemTemplate>
        <b><%#Eval("EventName")%></b>
        <asp:Repeater ID="rep_Actions" runat="server" Datasource='<%#Eval("Actions") %>'>
            <ItemTemplate>
                <blockquote>
                    <%#Eval("ActionName")%> <br />
                    <asp:DropDownList ID="dd_participants" runat="server" DataSource='<%# Eval("Participants") %>' DataTextField='<%# Eval("ParticipantName") %>' DataValueField='<%#Eval("ParticipantId")%>'>
                    </asp:DropDownList>
                </blockquote>
            </ItemTemplate>
         </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>

错误发生在 asp:DrowDownList,指出 VB$AnonymousType_1 不包含名为 ParticipantName 的属性。

DataBinding: 'VB$AnonymousType_1`3[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral,  PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.IEnumerable`1[[VB$AnonymousType_2`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], App_Web_2earclkn, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' does not contain a property with the name 'ParticipantName'.

我尝试使用 .ToList 和 .AsEnumerable 转换参与者,但仍然出现错误。

任何帮助将不胜感激。

谢谢!

【问题讨论】:

    标签: asp.net vb.net entity-framework linq ienumerable


    【解决方案1】:

    当然这属于第二个列表,Actions 没有 ParticipantName 属性。该属性在第三个列表的项目中。因此,您可以按如下方式更改代码:

     <asp:DropDownList ID="dd_participants" runat="server" DataSource='<%# Eval("Participants") %>' DataTextField="ParticipantName" DataValueField="ParticipantId">
                    </asp:DropDownList>
    

    希望对您有所帮助。

    【讨论】:

    • 是的!这就说得通了!谢谢!
    猜你喜欢
    • 2014-12-18
    • 2016-05-12
    • 2011-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多