Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# GridView未绑定列错误_C#_Asp.net_Gridview_Devexpress - Fatal编程技术网

C# GridView未绑定列错误

C# GridView未绑定列错误,c#,asp.net,gridview,devexpress,C#,Asp.net,Gridview,Devexpress,我将ASP.NET MVC与DevExpress一起使用,我在视图中插入了一个gridview(使用其部分和内容自动生成),我想在其中添加一个未绑定的列。 @{ var grid = Html.DevExpress().GridView(settings => { //configuration code and other columns settings.Columns.Add(c => {


我将ASP.NET MVC与DevExpress一起使用,我在视图中插入了一个gridview(使用其部分和内容自动生成),我想在其中添加一个未绑定的列。

@{
    var grid = Html.DevExpress().GridView(settings =>
    {
        //configuration code and other columns
        settings.Columns.Add(c =>
        {
            c.FieldName = "ClientFinal";
            c.Caption = "Client Final";
            c.UnboundType = DevExpress.Data.UnboundColumnType.String;
            c.UnboundExpression = "[Prenom] + ' ' + [Nom]";
        });
//configuration code
    });
}
@grid.Bind(Model).GetHtml()
客户最终实体:

public class ClientFinal : XPObject
    {
        public ClientFinal(Session session) : base(session) { }
        public override void AfterConstruction() { base.AfterConstruction(); }

        private string nom;
        public string Nom
        {
            get { return nom; }
            set { SetPropertyValue<string>("Nom", ref nom, value); }
        }

        private string prenom;
        public string Prenom
        {
            get { return prenom; }
            set { SetPropertyValue<string>("Prenom", ref prenom, value); }
        }
//other attributes
    }
public类ClientFinal:XPObject
{
公共客户端最终(会话):基本(会话){}
公共重写void AfterConstruction(){base.AfterConstruction();}
私有字符串名称;
公共字符串名称
{
获取{return nom;}
set{SetPropertyValue(“Nom”,ref Nom,value);}
}
私有字符串prenom;
公共字符串Prenom
{
获取{return prenom;}
set{SetPropertyValue(“Prenom”,ref Prenom,value);}
}
//其他属性
}
结果:

我甚至试过:
c.UnboundExpression=“[ClientFinal.Prenom]+”+[ClientFinal.Nom]但它不起作用。

请帮忙。


最后我解决了这个问题,问题是devexpress文档中没有很好地解释未绑定列功能。
第一:

c.FieldName = "ClientFinalUnbound";
属性FieldName必须是唯一的,它只是列的名称,而不是相关实体(网格中显示的)中现有字段的映射

第二:

c.UnboundExpression = "[ClientFinal.Prenom] + ' ' + [ClientFinal.Nom]";
在未绑定表达式中,字段必须是现有字段(列为实体定义中的属性或实体定义中属性的子元素),因此这里我调用集合实体中ClientFinal属性(网格中显示的属性)的Prenom(或Nom)属性


谢谢

您演示的代码绝对正确。设置网格列的FieldName属性似乎是不必要的,但不应导致错误。因此,我认为错误在于您没有显示的代码。问题代码已全部显示(如果我删除它,它将不会出现任何带有#Err的列)。如果操作中涉及任何其他代码,请告诉我我将发布它。谢谢,我不知道哪个代码可能是罪魁祸首。错误可能存在于您自己的代码中,也可能存在于DevExpress库中。我可以肯定的是,根据官方文档,您的代码很好。如果我是你,我会检查在打开有问题的页面时是否抛出任何CLR异常。异常消息可能包含有助于理解其原因的信息。我尝试调试并添加了所有断点,但没有引发异常:/