Search code examples
c#-4.0entity-framework-4devexpressaspxgridview

adding ASPxGridView to page with ObjectDataSource programmatically


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?


Solution

  • Another solution:

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