ASP.NET Repeater错误:找不到类型xx的默认成员

时间:2012-03-12 19:22:01

标签: asp.net repeater

这是我的.aspx页面中的转发器控件:

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

这是我的代码隐藏:

    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

我收到一条错误说:

No default member found for type 'Agenda'.

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

尝试使用以下修改后的代码

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

应该是这个DirectCast(e.Item.DataItem, YourClass).YourProperty