Welcome Guest Search | Active Topics | Sign In | Register

Populating Grid with bussiness entity Options
respall
Posted: Monday, January 14, 2008 1:01:18 AM
Rank: Newbie
Groups: Member

Joined: 1/14/2008
Posts: 1
Hi,

I'm evaluating VS 2005 with EO.Web Grid.
I use EO.WEB Controls Suite 2007.2 with ASP.NET 2.0.

I'm havving troubles populating from with a Entities data collection. This collection is populated with entities of type DataEntry (code bellow)


Code: C#
{
	public class DataEntry
    {
        public CodYear EntryID { get; set; }
	    public string Description { get; set; }
	    public decimal Ammount { get; set; }

        public DataEntry(CodYear id, string desc,  decimal amm)
        {
            EntryID = id; 
            Description = desc;
            Ammount = amm;
        }
    }
}

//
{
    public struct CodYear
    {
        public short Year;
        public int Number;

        public CodYear(short year, int number)
        {
            Year= year;
            Number = number;
        }

        public override string ToString()
        {
            return String.Format("{0} - {1}", Year, Number);
        }

    }


I have two problems with this:
1º. the first column, binding CodYear propety is displaye empty by the grid. I've overrided the ToString() method to try to solve it but it's still not woking.
The dode for this column is:
Code: HTML/ASPX
<eo:StaticColumn DataField="CodYear" HeaderText="Nº" 
                Name="EntryID" Width="60" DataFormat="{0}">
            </eo:StaticColumn>

I've tryed with and without the DataFormat attribute, with no result.

2º The column displaying the Ammount property is always displaying integer data, but the property is a decimal(10,2) value.
The code for this column is:
Code: HTML/ASPX
<eo:TextBoxColumn DataField="Ammount" DataFormat="{0:N2}" HeaderText="Importe">
            </eo:TextBoxColumn>

I've tryed with DataFormat="{0:N2}" and DataFormat="{0:D2}".

Do you have any idea how can I solve this?

Thanks in advance,
Ricardo
eo_support
Posted: Monday, January 14, 2008 7:04:34 AM
Rank: Administration
Groups: Administration

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

You won't be able feed a grid cell an arbitrary object like CodYear. While each row can populate from a complex object (in your case, DataEntry), each cell must populate from a simple value (such as integer, float, string, etc), similar to what you can store in a traditional relational database. The reason is Grid needs to keep the values of all these cells in ViewState and possibly edit and change it later on the client side, and it's impossible to do so with an arbitrary object. In your case, the easiest way for you is to define an additional property, for example, CodYearAsString on your DataEntry object and set the grid columns' DataField to "CodYearAsString".

For the second question, please download the latest version first. It fixed a number of Grid culture/format related issues. The latest version should display the value correctly. However, it will ignore DataFormat when the cell is in edit mode. For example, if DataFormat is {0:N4} and the value is 1.23, it will display it as "1.2300", however it will become "1.23" when the cell enters edit mode (thus display "1.23" in the textbox). It will again display "1.2300" once you leave the edit mode. The reason that DataFormat is ignored in edit mode is, edit mode also needs to convert the value back, and it's not possible to always convert the value back if DataFormat is used. For example, if DataFormat is "abc", then every value is converted to "abc" and the Grid can never convert "abc" back to its original value.

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.