错误:A field or property with the name 'XXX' was not found on the selected data source 解决

来源:互联网 发布:淘宝客服打电话说退款 编辑:程序博客网 时间:2024/05/22 02:06

 

有时候, 我绑定一个datasource到grid,会出现以下错误问题:

 

A field or property with the name 'To' was not found on the selected data source

 

 

 

 

原因:

datasource的item对象中,没有property

比如:

 

 public class Email
 {
        public string From = "";
        public string To = "";
        public string Subject = "";
        public string Body = "";

 }

这是不可以的,

 

 

 

解决方案:

 

应该改成这样!

 

 public class Email
    {
        private string _from = "";
        private string _to = "";
        private string _subject = "";
        private string _body = "";

        public string To
        {
            get { return _to; }
            set { _to = value; }
        }

        public string From
        {
            get { return _from; }
            set { _from = value; }
        }

        public string Subject
        {
            get { return _subject; }
            set { _subject = value; }
        }

        public string Body
        {
            get { return _body; }
            set { _body = value; }
        }
    }

 

 

原创粉丝点击