【问题标题】:DataBinding to GridView数据绑定到 GridView
【发布时间】:2010-05-08 11:19:34
【问题描述】:

我有一个 gridview 对象,我想将它绑定到一个对象。

我的对象是

public class BindingObject
{
    public ColorInfo Color { get; set; }
    public string Name { get; set; }

    public struct ColorInfo 
    {
        public string Red { get; set; }
        public string Green { get; set; }
        public string Blue { get; set; }
    }
}

我希望在 gridview 中只看到属性 NameRed 现在,当我绑定它时,我的 gridview 如下所示:ColorName,但我想要 RedName

我该怎么做?

谢谢。

更新:谢谢,但如果我想添加属性设置器

public string Red { 
    get { return this.Color.Red; } 
    set { this.Color.Red = value; } 
} 

我得到这个错误:

错误 1 ​​无法修改 'DataBinding.BindingObject.Color' 的返回值 因为它不是变量

感谢您的快速回复

【问题讨论】:

  • ASP .NET 还是 WinForms GridView ?有很大的不同。

标签: c# .net data-binding gridview


【解决方案1】:

将 ColorInfo 从结构更改为类或使用此结构中的字段而不是属性。

    public struct ColorInfo 
    {
        public string Red;
        public string Green;
        public string Blue;
    }

【讨论】:

    【解决方案2】:

    红绿蓝都是关键词,请避免使用关键词

    【讨论】:

      猜你喜欢
      • 2012-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-26
      • 2018-11-24
      • 1970-01-01
      相关资源
      最近更新 更多