Displaying a DataTable within a DataGrid cell ASP.NET

Discussion in 'ASP .Net Web Controls' started by mr killer, Sep 29, 2004.

  1. mr killer

    mr killer Guest

    I have an ASP.NET application simply displaying a DataGrid control on a form.
    Within some of the DataGrid cells I display multiple records within that
    cell based on an SQL query that loops through some table records.
    Unfortunately I can't format those records to be on there own separate line
    within the DataGrid cell, because the cell obviously just displays my results
    one after the other in the same cell. What I want to do is populate a
    separate DataTable, and store each record I grab in my query into its' own
    row within that DataTable. Then I want to display that DataTable within a
    specified DataGrid cell so the data will look stacked within the cell. This
    stems of the fact that HTML developers use tables for positioning data on a
    web-form, so I want to see if I can do the same thing within an ASP.NET
    DataGrid control. Is this possible? Thanks.
    mr killer, Sep 29, 2004
    #1
    1. Advertising

  2. You might want to see whether the free HierarGrid control will help you
    there:

    http://www.denisbauer.com/ASPNETControls/HierarGrid.aspx


    "mr killer" <> wrote in message
    news:...
    >I have an ASP.NET application simply displaying a DataGrid control on a
    >form.
    > Within some of the DataGrid cells I display multiple records within that
    > cell based on an SQL query that loops through some table records.
    > Unfortunately I can't format those records to be on there own separate
    > line
    > within the DataGrid cell, because the cell obviously just displays my
    > results
    > one after the other in the same cell. What I want to do is populate a
    > separate DataTable, and store each record I grab in my query into its' own
    > row within that DataTable. Then I want to display that DataTable within a
    > specified DataGrid cell so the data will look stacked within the cell.
    > This
    > stems of the fact that HTML developers use tables for positioning data on
    > a
    > web-form, so I want to see if I can do the same thing within an ASP.NET
    > DataGrid control. Is this possible? Thanks.
    >
    >
    Ken Cox [Microsoft MVP], Sep 30, 2004
    #2
    1. Advertising

  3. mr killer

    TenDot Guest

    Killer,

    I'm not a great expert but one way to do this would be to pull 2 queries,
    one for your parent table and one for your child table. Load them both into
    the same dataset so you've got ds.Tables[0] and ds.Tables[1]. Then build a
    relationship between the tables. When you put that into a grid you get a
    list of parent records with a button that will show the child records.
    Something like this:

    DataSet dsDD = new DataSet( "CPRdd" );
    string sqlCmd = "Select * from cprTables";
    SqlDataAdapter da = new SqlDataAdapter( sqlCmd, this._cnxnCPRdd );
    /// set up the tables in the DataSet
    da.Fill( dsDD, "Tables" );
    da.SelectCommand.CommandText = "Select * from cprFields order by FldName";
    da.Fill( dsDD, "Fields" );
    da.SelectCommand.CommandText = "Select * from TblComments order by
    TblName";
    da.Fill( dsDD, "TblCmts" );
    da.SelectCommand.CommandText = "Select * from FldComments order by
    FldName";
    da.Fill( dsDD, "FldCmts" );

    /// -----------------------------------------------------------
    /// build the relations for each table:
    /// -----------------------------------------------------------
    /// Tables table to Fields
    dsDD.Relations.Add( "TableFields",
    dsDD.Tables["Tables"].Columns["Pk_table"],dsDD.Tables["Fields"].Columns["TblKey"]);
    /// relate Comments to Tables
    dsDD.Relations.Add( "TableComment",
    dsDD.Tables["Tables"].Columns["TblName"],dsDD.Tables["TblCmts"].Columns["TblName"]);

    I hope that helps.



    "mr killer" wrote:

    > I have an ASP.NET application simply displaying a DataGrid control on a form.
    > Within some of the DataGrid cells I display multiple records within that
    > cell based on an SQL query that loops through some table records.
    > Unfortunately I can't format those records to be on there own separate line
    > within the DataGrid cell, because the cell obviously just displays my results
    > one after the other in the same cell. What I want to do is populate a
    > separate DataTable, and store each record I grab in my query into its' own
    > row within that DataTable. Then I want to display that DataTable within a
    > specified DataGrid cell so the data will look stacked within the cell. This
    > stems of the fact that HTML developers use tables for positioning data on a
    > web-form, so I want to see if I can do the same thing within an ASP.NET
    > DataGrid control. Is this possible? Thanks.
    >
    >
    TenDot, Oct 1, 2004
    #3
    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. J. Babe
    Replies:
    1
    Views:
    8,317
    Kevin Spencer
    Aug 15, 2003
  2. Fredrik Rodin

    Sort a datatable and create a new datatable

    Fredrik Rodin, Feb 16, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    9,031
    paul.mariotti
    Sep 28, 2007
  3. =?Utf-8?B?Qmx1ZWZsb3dlcg==?=

    Casting DataTable to class inherit from DataTable

    =?Utf-8?B?Qmx1ZWZsb3dlcg==?=, Apr 2, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    987
    =?Utf-8?B?Qmx1ZWZsb3dlcg==?=
    Apr 2, 2004
  4. Phillip Roncoroni
    Replies:
    14
    Views:
    1,074
    Toby A Inkster
    Apr 5, 2004
  5. mr killer

    Displaying a DataTable within a DataGrid cell

    mr killer, Sep 29, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    101
    mr killer
    Sep 29, 2004
Loading...

Share This Page