"数据绑定:'指数+ NewsItem'不包含名为'链接'&QUOT属性;但是属性存在(不是笔误) [英] "DataBinding: 'index+NewsItem' does not contain a property with the name 'Link'", but property exists (Not a Typo)

查看:148
本文介绍了"数据绑定:'指数+ NewsItem'不包含名为'链接'&QUOT属性;但是属性存在(不是笔误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我有一个中继器,而我输出特性。我曾经尝试都

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

<%#Eval("Link")%>

<%#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();

和我得到的数据绑定:'指数+ NewsItem不包含名为连接的属性。

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

推荐答案

您已经创建领域,而不是属性。

You have created fields, not properties

把它们变成属性,调整你的code这样

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;
     }
}  

这篇关于&QUOT;数据绑定:'指数+ NewsItem'不包含名为'链接'&QUOT属性;但是属性存在(不是笔误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆