Welcome Guest Search | Active Topics | Sign In | Register

Grid column named 'ID' Options
TMcCabe
Posted: Monday, April 28, 2014 6:27:35 PM
Rank: Member
Groups: Member

Joined: 12/9/2010
Posts: 28
I have a few Grid controls hooked to my data source. I am using Entity Framework CodeFirst. All of my model types have a GUID property called 'ID' as the key. My types are inheriting ID from an abstract base type (through a couple of layers of inheritance).

In one case, I'm using an proxy type where I have renamed this to 'RowID' and I have several other Guid 'ID's. The grid using this type works fine, and all of the GUID IDs are available as expected. All of the Guid columns in this case are prefixed: RowID, AID, BID, CID, etc. In this case, there is no inheritance, and all of the 'IDs' are in the base class.

In two other grids, I'm binding the grid to an IEnumerable<type> and setting a static column to use the DataField 'ID'. In these cases, the ID is not displayed or available in the GridItem -- the cell is always empty.

Code: HTML/ASPX
<Columns>
        <eo:RowNumberColumn>
        </eo:RowNumberColumn>
        <eo:StaticColumn DataField="Name" HeaderText="Name" Name="Name">
        </eo:StaticColumn>
        <eo:StaticColumn DataField="ID" HeaderText="ID" Name="ID">
        </eo:StaticColumn>
    </Columns>


I have also tried setting the Grid KeyField to 'ID', and this also is consistently coming back as empty.

Note that the Grids in all cases are within user controls, and the databinding occurs within the overriddent DataBind of the user control.

Is there something special about the field name 'ID' or the field name ID as a GUID?

Another column in the type is dispalying (plain string). I have experimented with setting the DataType to Auto and to String without luck.


Code: C#
pseudocode
public override void DataBind
{
   try
   {
       IEnumerable <myType> returnValue = repository.GetMyType();
       this.Grid1.DataSource = returnValue;
       this.Grid1.DataBind;
   }
   catch (Exception ex)
   {
     logger.log(ex);
   }
}


When I debug, I can see the ID is in the returnValue (base type) for myType. Other properties in the base type will show up in the grid. So, I know that the value is there (at least at the time of databinding in the code behind), and I know that I can display content from the same level of the inheritance tree. I know I can see Guids (not named ID) from another Grid. I'm just not able to see the Guid 'ID' property.

Is there something that I should be looking for?
eo_support
Posted: Monday, April 28, 2014 9:02:26 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

No. There is no special logic regarding ID. You can check whether ID property is public because we only check public property. The code that gets the cell data is something like this:

Code: C#
pseudocode
//Get all public properties
PropertyInfo[] properties = dataItemValue.GetType().GetProperties();

//Search one that matches the specified property name and get
//the value of that property
foreach (PropertyInfo p in properties)
{
    if (p.Name == propName)
        return p.GetValue(dataItemValue);
}


Thanks!
TMcCabe
Posted: Tuesday, April 29, 2014 8:55:36 AM
Rank: Member
Groups: Member

Joined: 12/9/2010
Posts: 28
Thank you for your quick reply.


My ID field is Public.

Code: C#
[DataContract]
    public abstract class MyBaseClass
    {
        [Required]
        [DataMember]
        public Guid ID { get; set; }

        [StringLength(40)]
        [DataMember]
        public String ModifiedBy { get; set; }
        [DataMember]
        public DateTime? Modified { get; set; }
        [DataMember]
        public String ModifiedApp { get; set; }

    }
	
	 [DataContract]
    public class MyEntity : MyBaseClass
    {
        [Required, StringLength(50)]
        [DataMember]
        public String Name { get; set; }
    }


Interestingly, if I swap the ModifiedBy or ModifiedBy properties of the same type into the column, those display fine. It is just the ID field that is giving me problems.

I'll try a proxy class like I used sucessfully in another grid and see if that gives me any hints. I would, of course, prefer to avoid having to use a proxy as an adapter since that obviates a lot of the simplicity of data binding.
TMcCabe
Posted: Tuesday, April 29, 2014 9:16:42 AM
Rank: Member
Groups: Member

Joined: 12/9/2010
Posts: 28
With a bit of work with a proxy class, the issue may be due to the fact that my ID property is a Guid. Rechecking the grid 'where it works' (with a proxy class), I find that I'd converted all of my Guids to Strings. Doing the same here also allows 'RowID' property to show, while the 'ID' property does not.

Code: C#
public class MyEntityProxy
    {
        public MyEntityProxy(MyEntity entity)
        {
            this.ID = entity.ID;
            this.RowID = entity.ID.ToString();
            this.Name = entity.Name;
        }

        public Guid ID { get; set; }
        public String RowID { get; set; }
        public String Name { get; set; }
    }
eo_support
Posted: Tuesday, April 29, 2014 11:06:21 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

You are correct. We have confirmed that the problem is caused by value type. Current it only supports basic value types (strings, integer, etc). We will update our code to call value.ToString() if the value type is not one of the basic types. So this should work in our next build.

Thanks!
eo_support
Posted: Tuesday, May 6, 2014 1:48:02 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

We have posted a new build that should support non basic types such as Guid. You can download the new build from our download page.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.