ComboBox 绑定customers( IList customers = new List();) 报错

asp_c 2007-10-13 02:37:49
IList<CustomInfo> customers = new List<CustomInfo>();//CustomerInfo是客户实体类
customers=customer.GetCustomers();//取所有客户信息
cbxCustomer.DataSource = customers;//cbxCustomer是ComboBox控件--------报错:未将对象引用设置到对象的实例
cbxCustomer.ValueMember = "CustomerID";
cbxCustomer.DisplayMember = "CustomerName";
...全文
289 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ojekleen 2007-10-13
  • 打赏
  • 举报
回复
if(!=null)
asp_c 2007-10-13
  • 打赏
  • 举报
回复
IList <CustomInfo > customers = new List <CustomInfo >();//CustomerInfo是客户实体类
customers=customer.GetCustomers();//取所有客户信息
cbxCustomer.DataSource = customers;//cbxCustomer是ComboBox控件--------报错:未将对象引用设置到对象的实例
cbxCustomer.ValueMember = "CustomerID";
cbxCustomer.DisplayMember = "CustomerName";

代码没错,可以使用了
asp_c 2007-10-13
  • 打赏
  • 举报
回复
这个控件有什么状态要设置吗,如编辑状态等啊
asp_c 2007-10-13
  • 打赏
  • 举报
回复
定义了啊
SDFDSAC 2007-10-13
  • 打赏
  • 举报
回复
CustomInfo 客户实体类里定义属性了吗?
string _customerId;
string CustomerId
{
get{return _customerId;}
set{_customerId=value;}
}
asp_c 2007-10-13
  • 打赏
  • 举报
回复
我那方法里就写了这些内容啊,customers里面是有内容的
CustomInfo 客户实体类里包括string CustomerId, string CustomerName, string Creator, System.DateTime CreatedTime, int Deleted, string Remark 这些字段
jeremyyang824 2007-10-13
  • 打赏
  • 举报
回复
这样看不出来啊,代码再全些。
你可以在报错的这句上添加个断点,然后看看customers的当前内容是什么

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧