1

I'm new to LINQ and was hoping to get some help from anyone that know how to transpose the data in a grid using linq to entities? Any help would be much appreciated. Thanks in advance.

from...

ID    Date        Amount
1      2/1/2012   100
2      2/2/2012   200
3      2/3/2010   300

to...

ID     1           2         3
Date   2/1/2012   2/2/2012   2/3/2012
Amount 100        200        300

etc...

I got this script and trying to use it for my purposes but I can't get it to work. Now I get this error message "'DBModel.Table1' does not contain a definition for 'Columns' and no extension method 'Columns' accepting a first argument of type 'DBModel.Table1' could be found (are you missing a using directive or an assembly reference?) and the same error message for rows "'DBModel.Table1' does not contain a definition for 'Rows'" --Bear with me Im coming from databases and sql world, so all help would be wonderful.

private Table1 GetTransposedTable(Table1 fc)
        {
            Table1 newTable = new Table1();
            newTable.Columns.Add(new DataColumn("0", typeof(string)));
            for (int i = 0; i < fc.Columns.Count; i++)
            {
                DataRow newRow = newTable.NewRow();
                newRow[0] = Convert.ToInt32(Session["Table1_ID"].ToString());
                for (int j = 1; j <= fc.Rows.Count; j++)
                {
                    if (newTable.Columns.Count < fc.Rows.Count + 1)
                        newTable.Columns.Add(new DataColumn(j.ToString(), typeof(string)));
                    newRow[j] = fc.Rows[j - 1][i];
                }
                newTable.Rows.Add(newRow);
            }
            return newTable;
                }
rZebra
  • 39
  • 4

1 Answers1

0

I would suggest using a templatable control, like ListView, rather than transforming the data if its possible. I guess part of it depends on how much functionality you have tied to the DataGrid, but I would think most of that would be wrecked by the change in format anyway.

Information on using a ListView can be found here: http://msdn.microsoft.com/en-us/library/bb398790.aspx.

Felan
  • 1,273
  • 10
  • 17