Orange Kid
Orange Kid

Reputation: 544

Group data in columns (instead of rows) in an HTML table using data bound control?

Is there a way to group data into columns using a data bound control in ASP.NET?

Normally, binding a control to an array of objects, I think of each object as a row. In a typical HTML table, the markup flows the same way and you get get something like this;

            HEADER1     HEADER2     HEADER3
Object1     Field1      Field2      Field3
Object2     Field1      Field2      Field3
Object3     Field1      Field2      Field3

What I want is this;

            Object1     Object2     Object3     
HEADER1     Field1      Field1      Field1
HEADER2     Field2      Field2      Field2
HEADER3     Field3      Field3      Field3

Outside of modifying the data so that each data item of the bound control holds all of Field1, then Field2, Field3, (instead of Object1, Object2, Object3,) I can't think of a way to do this.

Note, I am using .NET 2.0 and am stuck with those controls.

This is an extension of my question here where I wanted to float DIVs with each DIV reflecting an object.

Upvotes: 1

Views: 778

Answers (1)

Morgan T.
Morgan T.

Reputation: 1937

Instead of rotating the control, how about rotating the data? I found this clever article on CodeProject that has a method to flip a DataSet on its axis: Vertical Rows in Datagrid

Here's a quick way to transpose an array:

public static void transpose(int[][] a, int[][] b, int width, int height){ 
  for (int i = 0; i < width; i++)
  {
    for (int j = 0; j < height; j++)
    {
      b[j][i] = a[i][j];
    }
  }
}

Upvotes: 0

Related Questions