Pivot a datagrid?

Discussion in 'ASP .Net Datagrid Control' started by et, Sep 17, 2005.

  1. et

    et Guest

    I seem to remember seeing an article on how to reverse the data in a grid,
    so that each record creates a column rather than a row? Does anyone know
    how to do this? Thanks for your help.
    et, Sep 17, 2005
    #1
    1. Advertising

  2. et

    Elton Wang Guest

    Once rendering to cliend-side, a datagrid actually is html table. Hence if
    you just want to show data in a grid, you can manually create html table
    based on your data source, in a revering row/column arrangement.



    Or you can reverse row/column in data source. For example, the data source
    is a 8 columns and 5 rows datatable, you create a datatable with 5 columns
    then assign data from first datatable to second datatable. After binding
    datagrid's data source to the second datatable, it shows data in a reversing
    behavior.



    HTH





    "et" <> wrote in message
    news:O6K4m%...
    >I seem to remember seeing an article on how to reverse the data in a grid,
    >so that each record creates a column rather than a row? Does anyone know
    >how to do this? Thanks for your help.
    >
    Elton Wang, Sep 18, 2005
    #2
    1. Advertising

  3. et

    eagle Guest

    That's an idea, although not sure how to do the second one. You mean item
    by item I would have to place into the 2nd table? Could you give me some
    code or pseudo code examples?

    I also want pagination, hence the reason I am sticking to a grid. Thanks
    for you rhelp.


    "Elton Wang" <> wrote in message
    news:...
    > Once rendering to cliend-side, a datagrid actually is html table. Hence if
    > you just want to show data in a grid, you can manually create html table
    > based on your data source, in a revering row/column arrangement.
    >
    >
    >
    > Or you can reverse row/column in data source. For example, the data source
    > is a 8 columns and 5 rows datatable, you create a datatable with 5 columns
    > then assign data from first datatable to second datatable. After binding
    > datagrid's data source to the second datatable, it shows data in a
    > reversing behavior.
    >
    >
    >
    > HTH
    >
    >
    >
    >
    >
    > "et" <> wrote in message
    > news:O6K4m%...
    >>I seem to remember seeing an article on how to reverse the data in a grid,
    >>so that each record creates a column rather than a row? Does anyone know
    >>how to do this? Thanks for your help.
    >>

    >
    >
    eagle, Sep 21, 2005
    #3
  4. et

    Elton Wang Guest

    Following is code snippet :

    DataTable secondTable = new DataTable();
    DataColumn col;
    for (int I = 0; I < datasource.Rows.Count; I++)
    {
    col = new DataColumn("Col" + I.ToString(),
    Type.GetType("System.String"));
    secondTable.Columns.Add(col);
    }

    DataRow newRow;
    for (int I = 0; I < datasource.Columns.Count; I++)
    {
    newRow = secondTable.NewRow();
    for (int J = 0; J< datasource.Rows.Count; J++)
    {
    newRow[J] = datasource.Rows[J].ToString();
    }
    secondTable.Rows.Add(newRow);
    }

    HTH

    "eagle" <> wrote in message
    news:...
    > That's an idea, although not sure how to do the second one. You mean item
    > by item I would have to place into the 2nd table? Could you give me some
    > code or pseudo code examples?
    >
    > I also want pagination, hence the reason I am sticking to a grid. Thanks
    > for you rhelp.
    >
    >
    > "Elton Wang" <> wrote in message
    > news:...
    > > Once rendering to cliend-side, a datagrid actually is html table. Hence

    if
    > > you just want to show data in a grid, you can manually create html table
    > > based on your data source, in a revering row/column arrangement.
    > >
    > >
    > >
    > > Or you can reverse row/column in data source. For example, the data

    source
    > > is a 8 columns and 5 rows datatable, you create a datatable with 5

    columns
    > > then assign data from first datatable to second datatable. After binding
    > > datagrid's data source to the second datatable, it shows data in a
    > > reversing behavior.
    > >
    > >
    > >
    > > HTH
    > >
    > >
    > >
    > >
    > >
    > > "et" <> wrote in message
    > > news:O6K4m%...
    > >>I seem to remember seeing an article on how to reverse the data in a

    grid,
    > >>so that each record creates a column rather than a row? Does anyone

    know
    > >>how to do this? Thanks for your help.
    > >>

    > >
    > >

    >
    >
    Elton Wang, Sep 21, 2005
    #4
  5. et

    et Guest

    that works! thanks so much for your help.

    "Elton Wang" <> wrote in message
    news:%...
    > Following is code snippet :
    >
    > DataTable secondTable = new DataTable();
    > DataColumn col;
    > for (int I = 0; I < datasource.Rows.Count; I++)
    > {
    > col = new DataColumn("Col" + I.ToString(),
    > Type.GetType("System.String"));
    > secondTable.Columns.Add(col);
    > }
    >
    > DataRow newRow;
    > for (int I = 0; I < datasource.Columns.Count; I++)
    > {
    > newRow = secondTable.NewRow();
    > for (int J = 0; J< datasource.Rows.Count; J++)
    > {
    > newRow[J] = datasource.Rows[J].ToString();
    > }
    > secondTable.Rows.Add(newRow);
    > }
    >
    > HTH
    >
    > "eagle" <> wrote in message
    > news:...
    >> That's an idea, although not sure how to do the second one. You mean
    >> item
    >> by item I would have to place into the 2nd table? Could you give me some
    >> code or pseudo code examples?
    >>
    >> I also want pagination, hence the reason I am sticking to a grid. Thanks
    >> for you rhelp.
    >>
    >>
    >> "Elton Wang" <> wrote in message
    >> news:...
    >> > Once rendering to cliend-side, a datagrid actually is html table. Hence

    > if
    >> > you just want to show data in a grid, you can manually create html
    >> > table
    >> > based on your data source, in a revering row/column arrangement.
    >> >
    >> >
    >> >
    >> > Or you can reverse row/column in data source. For example, the data

    > source
    >> > is a 8 columns and 5 rows datatable, you create a datatable with 5

    > columns
    >> > then assign data from first datatable to second datatable. After
    >> > binding
    >> > datagrid's data source to the second datatable, it shows data in a
    >> > reversing behavior.
    >> >
    >> >
    >> >
    >> > HTH
    >> >
    >> >
    >> >
    >> >
    >> >
    >> > "et" <> wrote in message
    >> > news:O6K4m%...
    >> >>I seem to remember seeing an article on how to reverse the data in a

    > grid,
    >> >>so that each record creates a column rather than a row? Does anyone

    > know
    >> >>how to do this? Thanks for your help.
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
    et, Sep 22, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWpheQ==?=

    Create Pivot table

    =?Utf-8?B?QWpheQ==?=, Feb 13, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    7,448
    Alvin Bruney [MVP]
    Feb 16, 2004
  2. =?Utf-8?B?UG9udGlNYXg=?=

    Pivot table control

    =?Utf-8?B?UG9udGlNYXg=?=, Jun 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    4,366
    Ken Cox [Microsoft MVP]
    Jun 15, 2004
  3. =?Utf-8?B?VGltX2s=?=

    Exporting datagrid to Excel Pivot Table

    =?Utf-8?B?VGltX2s=?=, Jan 26, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    630
    =?Utf-8?B?VGltX2s=?=
    Jan 26, 2005
  4. =?Utf-8?B?Sm9u?=

    DataGrid Pivot

    =?Utf-8?B?Sm9u?=, May 16, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    451
    =?Utf-8?B?Sm9u?=
    May 19, 2006
  5. Brian Pittman

    Pivot data in editable datagrid. Possible or not?

    Brian Pittman, Sep 25, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    214
    Brian Pittman
    Sep 25, 2003
Loading...

Share This Page