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(我假设您使用的是实体框架)。