Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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# 4.0 以编程方式将ASPxGridView添加到带有ObjectDataSource的页面_C# 4.0_Entity Framework 4_Devexpress_Aspxgridview - Fatal编程技术网

C# 4.0 以编程方式将ASPxGridView添加到带有ObjectDataSource的页面

C# 4.0 以编程方式将ASPxGridView添加到带有ObjectDataSource的页面,c#-4.0,entity-framework-4,devexpress,aspxgridview,C# 4.0,Entity Framework 4,Devexpress,Aspxgridview,我正在尝试将ASPxGridView添加到页面,并以编程方式将其绑定到ObjectDataSource 这是我的密码: protected void Page_Init(object sender, EventArgs e) { ObjectDataSource odsGroup = new ObjectDataSource(); var gridLookup = new ASPxGridView(); odsGroup.ID = "od

我正在尝试将
ASPxGridView
添加到页面,并以编程方式将其绑定到
ObjectDataSource

这是我的密码:

protected void Page_Init(object sender, EventArgs e)
    {
        ObjectDataSource odsGroup = new ObjectDataSource();
        var gridLookup = new ASPxGridView();

        odsGroup.ID = "odsGroups";
        odsGroup.SelectMethod = "GetAllElements";
        odsGroup.TypeName = "Ifa.BusinessLayer.BLLClasses.GroupBll";
        odsGroup.OldValuesParameterFormatString = "original_{0}";

        gridLookup.ViewStateMode = ViewStateMode.Disabled;


        gridLookup.ID = "groupsLookup";
        gridLookup.AutoGenerateColumns = true;
        gridLookup.DataSource = odsGroup;
        gridLookup.KeyFieldName = "Id";
        gridLookup.DataBind();
        pnl1.Controls.Add(gridLookup);
    }
当我使用
GridView
而不是
ASPxGridView
时,此代码运行良好,但正如我所说,它不适用于
ASPxGridView
并抛出
System.Runtime.Serialization.SerializationException

例外情况:


任何解决方案?

此问题可能与IIS的安全设置和相应权限有关。必要时,ASPxGridView从缓存反序列化数据行。通过将ASPxGridView.EnableRowsCache属性设置为“False

另一个解决方案,禁用ASPxGridView的缓存:

  gridLookup.Columns.Add(new GridViewDataColumn("Name"));
  gridLookup.AutoGenerateColumns = false;

尝试将grid EnableViewState设置为false。如果这对标记没有帮助的话。我已经检查了你的解决方案,它们不起作用。在生成IFEntities1后,我在程序集System.Data.Entity中遇到类型异常“System.Data.Objects.ObjectContext”,版本=4.0.0.0,区域性=neutral,PublicKeyToken=b77a5c561934e089”未标记为可序列化。请尝试将网格绑定到EntityDatasource(我假设您使用的是实体框架)。