数据绑定:"Data.Edu.Nyp.Crm.Contact.Country"不包含名称为"id"的属性. [英] DataBinding: 'Data.Edu.Nyp.Crm.Contact.Country' does not contain a property with the name 'id'.

查看:58
本文介绍了数据绑定:"Data.Edu.Nyp.Crm.Contact.Country"不包含名称为"id"的属性.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码.突出显示的部分应该是错误所在.这段代码在我的app_code中.

公共静态无效InitCountryDDL(DropDownList ddl,List< Country>国家/地区)
{
ddl.DataSource =国家/地区;
ddl.DataTextField = Country.NAME;
ddl.DataValueField = Country.ID;
ddl.DataBind();
}

这是我声明我的ID和名称的另一个代码.

命名空间Data.Edu.Nyp.Crm.Contact
{
公共课程国家/地区
{
公共静态字符串ID ="id";
公共静态字符串NAME =名称";

私有字符串ID;
私有字符串名称;

公共字符串CountryId
{
得到{返回ID; }
设置{id =值; }
}

公共字符串名称
{
得到{返回名称; }
设置{名称=值; }
}
}
}

Here''s my code. the highlighted piece is where the error is supposed to be. this piece of code is in my app_code.

public static void InitCountryDDL(DropDownList ddl, List<Country> countries)
{
ddl.DataSource = countries;
ddl.DataTextField = Country.NAME;
ddl.DataValueField = Country.ID;
ddl.DataBind();
}

Here is another code in where i declared my id and name.

namespace Data.Edu.Nyp.Crm.Contact
{
public class Country
{
public static string ID = "id";
public static string NAME = "name";

private string id;
private string name;

public string CountryId
{
get { return id; }
set { id = value; }
}

public string Name
{
get { return name; }
set { name = value; }
}
}
}

推荐答案

好,这有点奇怪.但是,它解释了该错误. ID必须为"CountryId". NAME必须为名称".它们区分大小写,您的代码无法正常工作,而我茫然为什么您认为它可以工作.您的私有变量是私有的,数据网格无法访问它们.实际上,它们必须是属性,而不是变量,因此会出现错误消息.
OK, that''s a bit odd. However, it explains the error. ID needs to be ''CountryId''. NAME needs to be ''Name''. They are case sensitive, your code couldn''t possibly work, and I''m at a loss why you thought it could. Your private variables are private, the datagrid cannot access them. In fact, they need to be a property, not a variable, hence the error message you got.


结果表明,Country类没有名称为"id"的属性.您确定这是您想要的,而不是"NAME"和"ID"吗?如果集合是Country类的实例,那么您需要将属性名称放在引号中,而不是用引号引起来.
Turns out that the Country class does not have a property with the name "id". Are you sure this is what you want to do, and not "NAME" and "ID" ? If the collection is of instances of the Country class, then you need to put the property names in quotes, not what you have done.


这篇关于数据绑定:"Data.Edu.Nyp.Crm.Contact.Country"不包含名称为"id"的属性.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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