ASP.NET Repeater Error: No default member found for type xx

我的梦境 提交于 2019-12-02 17:25:24

问题


This is my repeater control in my .aspx page:

    <asp:Repeater ID="rptEvents" runat="server">
        <ItemTemplate>
            <div><asp:HyperLink ID="hypItem" Text="sss" NavigateUrl="#" runat="server"></asp:HyperLink></div>
        </ItemTemplate>
    </asp:Repeater>

And this is my codebehind:

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            rptEvents.DataSource = KTOEOS.Agenda.GetAgendaItems // returns a List(Of Agenda)
// Where Agenda is my object (created successfully)
            rptEvents.DataBind()
        End If
    End Sub


    Protected Sub rptEvents_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptEvents.ItemDataBound
        If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
            Dim c As HyperLink = e.Item.FindControl("hypItem")
            c.Text = DateTime.Now & " > " & e.Item.DataItem("Date")
        End If
    End Sub

And I receive an error saying:

No default member found for type 'Agenda'.

Any ideas?


回答1:


Try with below Modified code

Dim c As HyperLink = DirectCast(e.Row.FindControl("hypItem"), HyperLink)

It should be like this DirectCast(e.Item.DataItem, YourClass).YourProperty



来源:https://stackoverflow.com/questions/9673445/asp-net-repeater-error-no-default-member-found-for-type-xx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!