2

I'm trying to add ASPxGridView to page and bind it to ObjectDataSource programmatically.

here is my code:

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);
    }

This code works fine when i use GridView instead of ASPxGridView, but as I said it does not work with ASPxGridView and throws System.Runtime.Serialization.SerializationException

exception: enter image description here

any solutions?

Cœur
  • 37,241
  • 25
  • 195
  • 267
r.zarei
  • 1,261
  • 15
  • 35
  • Try setting grid EnableViewState to false. If that doesn't help try marking [IfaEntities1 with Serializable attribute](http://stackoverflow.com/questions/2756592/entity-framework-4-0-autogenerated-classes-not-marked-as-serializable). – Filip Jul 03 '12 at 07:21
  • I've check your solution, they did not worked. after making IfaEntities1 I've got Type exception 'System.Data.Objects.ObjectContext' in Assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable. – r.zarei Jul 03 '12 at 13:46
  • Try binding grid to EntityDatasource (I assumed you are using Entity framework). [Example from DevEx site](http://www.devexpress.com/Support/Center/e/E3251.aspx). – Filip Jul 03 '12 at 14:21

2 Answers2

2

This problem may be related to the IIS's secure settings and corresponding permissions. ASPxGridView deserializes data rows from its cache when it's necessary. Disable the ASPxGridView's cache by setting the ASPxGridView.EnableRowsCache property to "False".

Mikhail
  • 9,186
  • 4
  • 33
  • 49
0

Another solution:

  gridLookup.Columns.Add(new GridViewDataColumn("Name"));
  gridLookup.AutoGenerateColumns = false;
r.zarei
  • 1,261
  • 15
  • 35