Reputation: 13742
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?
Upvotes: 0
Views: 3102
Reputation: 10095
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
Upvotes: 1