GridView bound with Properties of nested class

后端 未结 2 1901
情书的邮戳
情书的邮戳 2020-11-29 10:48

I have an object map similar to what\'s listed below. When I try to bind the properties of NestedClass in a GridView I get the error:

\"A field or pro

2条回答
  •  温柔的废话
    2020-11-29 11:29

    This extension on BoundField calls DataBinder.Eval(), which does support nested properties:

    public class BetterBoundField : BoundField
    {
        protected override object GetValue(Control controlContainer)
        {
            if (DataField.Contains("."))
            {
                var component = DataBinder.GetDataItem(controlContainer);
                return DataBinder.Eval(component, DataField);
            }
            return base.GetValue(controlContainer);
        }
    }
    

提交回复
热议问题