"DataBinding: 'index+NewsItem' does not contain a property with the name 'Link'", but property exists (Not a Typo)
Asked Answered
E

1

20

First I have a repeater, and I'm outputting a property. I have tried both

<%#Eval("Link")%>

and

<%#DataBinder.Eval(Container.DataItem, "Link")%>

I have a simple class

public class NewsItem  
{  
    public string Link = "";  
    public string Title = "";  
}  

I populate a List news with with a simple for... each, and then...

repeater.DataSource = news;
repeater.DataBind();

and I get "DataBinding: 'index+NewsItem' does not contain a property with the name 'Link'

Eyde answered 1/9, 2011 at 14:2 Comment(0)
S
36

You have created fields, not properties

To turn them into properties, adjust your code like this

public class NewsItem  
{  
     public string Link { get; set; }
     public string Title { get; set; }              

     public NewsItem()
     {
           this.Link = string.Empty;
           this.Title = string.Empty;
     }
}  
Starknaked answered 1/9, 2011 at 14:4 Comment(2)
Thank you, I did not think it would care about that, but indeed it does.Eyde
I find the constructor unnecessaryFishback

© 2022 - 2024 — McMap. All rights reserved.