dataGrid in DataGrid

Discussion in 'ASP .Net Datagrid Control' started by BK Kim, Feb 23, 2004.

  1. BK Kim

    BK Kim Guest

    Hello.

    I am trying to use dataGrid in a dataGrid, meaning first DataGrid displays
    some information and on each row, it is going to have another datagrid to
    display detailed information.

    I was able to do it in two dataGrid. ( one datagrid containing a datagrid in
    each row )

    But I was not able to do it in three dataGrid.

    Generally, I bind the first DataGrid and on ItemCreated event, I add a cell
    into that row containing dataGrid. ( works fine )

    private void grdTemp_ItemCreated(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)

    {

    if( e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem )

    {

    System.Web.UI.WebControls.DataGrid grdTemp2 = new DataGrid();

    grdTemp2.ItemCreated += new
    System.Web.UI.WebControls.DataGridItemEventHandler(this.grdTemp2_ItemCreated
    );

    e.Item.Cells[0].Controls.Add(grdTemp2);


    grdTemp2.DataSource = getData(2);

    grdTemp2.DataBind();

    }


    }

    private void grdTemp2_ItemCreated(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)

    {

    if( e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem )

    {

    System.Web.UI.WebControls.DataGrid grdTemp3 = new DataGrid();


    grdTemp3.DataSource = getData(3);

    grdTemp3.DataBind();

    e.Item.Cells[0].Controls.Add(grdTemp3);


    }

    }


    Does anyone knows, how to do this or why this code doesn't work?
    Thanx in advance
     
    BK Kim, Feb 23, 2004
    #1
    1. Advertising

  2. You are trying to build drill thru functionality from what i can see. You
    are taking an unnecessary complex route. One approach which works well is to
    have a details button along with each row displayed in the grid. Clicking
    details on this button means you want details for that particular row, so
    you grab the relevant row data, build a query with a whereclause based on
    the selected row and go grab that specific data to display in the datagrid.
    The new datagrid also contains a details button. In that way, you can drill
    infinitely without having to keep track of anything, all you need is the
    selected row to build your where clause part of the query. Make sense?

    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "BK Kim" <> wrote in message
    news:%235iDikk%...
    > Hello.
    >
    > I am trying to use dataGrid in a dataGrid, meaning first DataGrid displays
    > some information and on each row, it is going to have another datagrid to
    > display detailed information.
    >
    > I was able to do it in two dataGrid. ( one datagrid containing a datagrid

    in
    > each row )
    >
    > But I was not able to do it in three dataGrid.
    >
    > Generally, I bind the first DataGrid and on ItemCreated event, I add a

    cell
    > into that row containing dataGrid. ( works fine )
    >
    > private void grdTemp_ItemCreated(object sender,
    > System.Web.UI.WebControls.DataGridItemEventArgs e)
    >
    > {
    >
    > if( e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > ListItemType.AlternatingItem )
    >
    > {
    >
    > System.Web.UI.WebControls.DataGrid grdTemp2 = new DataGrid();
    >
    > grdTemp2.ItemCreated += new
    >

    System.Web.UI.WebControls.DataGridItemEventHandler(this.grdTemp2_ItemCreated
    > );
    >
    > e.Item.Cells[0].Controls.Add(grdTemp2);
    >
    >
    > grdTemp2.DataSource = getData(2);
    >
    > grdTemp2.DataBind();
    >
    > }
    >
    >
    > }
    >
    > private void grdTemp2_ItemCreated(object sender,
    > System.Web.UI.WebControls.DataGridItemEventArgs e)
    >
    > {
    >
    > if( e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > ListItemType.AlternatingItem )
    >
    > {
    >
    > System.Web.UI.WebControls.DataGrid grdTemp3 = new DataGrid();
    >
    >
    > grdTemp3.DataSource = getData(3);
    >
    > grdTemp3.DataBind();
    >
    > e.Item.Cells[0].Controls.Add(grdTemp3);
    >
    >
    > }
    >
    > }
    >
    >
    > Does anyone knows, how to do this or why this code doesn't work?
    > Thanx in advance
    >
    >
     
    Alvin Bruney [MVP], Feb 24, 2004
    #2
    1. Advertising

  3. BK Kim

    BK Kim Guest

    If I have that option, I wouldn't worry about this but I cannot approach in
    that way.

    In our requirement spec, we have our demo to follow( which is not what you
    just discribed )

    Is there any other way to achieve this?

    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    news:uKTSKGn%...
    > You are trying to build drill thru functionality from what i can see. You
    > are taking an unnecessary complex route. One approach which works well is

    to
    > have a details button along with each row displayed in the grid. Clicking
    > details on this button means you want details for that particular row, so
    > you grab the relevant row data, build a query with a whereclause based on
    > the selected row and go grab that specific data to display in the

    datagrid.
    > The new datagrid also contains a details button. In that way, you can

    drill
    > infinitely without having to keep track of anything, all you need is the
    > selected row to build your where clause part of the query. Make sense?
    >
    > --
    > Regards,
    > Alvin Bruney [ASP.NET MVP]
    > Got tidbits? Get it here...
    > http://tinyurl.com/3he3b
    > "BK Kim" <> wrote in message
    > news:%235iDikk%...
    > > Hello.
    > >
    > > I am trying to use dataGrid in a dataGrid, meaning first DataGrid

    displays
    > > some information and on each row, it is going to have another datagrid

    to
    > > display detailed information.
    > >
    > > I was able to do it in two dataGrid. ( one datagrid containing a

    datagrid
    > in
    > > each row )
    > >
    > > But I was not able to do it in three dataGrid.
    > >
    > > Generally, I bind the first DataGrid and on ItemCreated event, I add a

    > cell
    > > into that row containing dataGrid. ( works fine )
    > >
    > > private void grdTemp_ItemCreated(object sender,
    > > System.Web.UI.WebControls.DataGridItemEventArgs e)
    > >
    > > {
    > >
    > > if( e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > > ListItemType.AlternatingItem )
    > >
    > > {
    > >
    > > System.Web.UI.WebControls.DataGrid grdTemp2 = new DataGrid();
    > >
    > > grdTemp2.ItemCreated += new
    > >

    >

    System.Web.UI.WebControls.DataGridItemEventHandler(this.grdTemp2_ItemCreated
    > > );
    > >
    > > e.Item.Cells[0].Controls.Add(grdTemp2);
    > >
    > >
    > > grdTemp2.DataSource = getData(2);
    > >
    > > grdTemp2.DataBind();
    > >
    > > }
    > >
    > >
    > > }
    > >
    > > private void grdTemp2_ItemCreated(object sender,
    > > System.Web.UI.WebControls.DataGridItemEventArgs e)
    > >
    > > {
    > >
    > > if( e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > > ListItemType.AlternatingItem )
    > >
    > > {
    > >
    > > System.Web.UI.WebControls.DataGrid grdTemp3 = new DataGrid();
    > >
    > >
    > > grdTemp3.DataSource = getData(3);
    > >
    > > grdTemp3.DataBind();
    > >
    > > e.Item.Cells[0].Controls.Add(grdTemp3);
    > >
    > >
    > > }
    > >
    > > }
    > >
    > >
    > > Does anyone knows, how to do this or why this code doesn't work?
    > > Thanx in advance
    > >
    > >

    >
    >
     
    BK Kim, Feb 24, 2004
    #3
  4. Hi Kim,
    Sounds like you have a master detail scenario.
    You can use a DataList and DataGrid together to acheive the same.
    Here is a very good article on this by Bipin Joshi.
    http://www.dotnetbips.com/displayarticle.aspx?id=184

    Hope this helps.
    Regards,
    Marshal Antony
    ..NET Developer
    http://www.dotnetmarshal.com



    "BK Kim" <> wrote in message
    news:%235iDikk%...
    > Hello.
    >
    > I am trying to use dataGrid in a dataGrid, meaning first DataGrid displays
    > some information and on each row, it is going to have another datagrid to
    > display detailed information.
    >
    > I was able to do it in two dataGrid. ( one datagrid containing a datagrid

    in
    > each row )
    >
    > But I was not able to do it in three dataGrid.
    >
    > Generally, I bind the first DataGrid and on ItemCreated event, I add a

    cell
    > into that row containing dataGrid. ( works fine )
    >
    > private void grdTemp_ItemCreated(object sender,
    > System.Web.UI.WebControls.DataGridItemEventArgs e)
    >
    > {
    >
    > if( e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > ListItemType.AlternatingItem )
    >
    > {
    >
    > System.Web.UI.WebControls.DataGrid grdTemp2 = new DataGrid();
    >
    > grdTemp2.ItemCreated += new
    >

    System.Web.UI.WebControls.DataGridItemEventHandler(this.grdTemp2_ItemCreated
    > );
    >
    > e.Item.Cells[0].Controls.Add(grdTemp2);
    >
    >
    > grdTemp2.DataSource = getData(2);
    >
    > grdTemp2.DataBind();
    >
    > }
    >
    >
    > }
    >
    > private void grdTemp2_ItemCreated(object sender,
    > System.Web.UI.WebControls.DataGridItemEventArgs e)
    >
    > {
    >
    > if( e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > ListItemType.AlternatingItem )
    >
    > {
    >
    > System.Web.UI.WebControls.DataGrid grdTemp3 = new DataGrid();
    >
    >
    > grdTemp3.DataSource = getData(3);
    >
    > grdTemp3.DataBind();
    >
    > e.Item.Cells[0].Controls.Add(grdTemp3);
    >
    >
    > }
    >
    > }
    >
    >
    > Does anyone knows, how to do this or why this code doesn't work?
    > Thanx in advance
    >
    >
     
    Marshal Antony, Feb 24, 2004
    #4
    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. Dave
    Replies:
    0
    Views:
    459
  2. BK Kim

    datagrid in datagrid

    BK Kim, Feb 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    553
    Alvin Bruney [MVP]
    Mar 2, 2004
  3. =?Utf-8?B?U3VyZXNo?=
    Replies:
    0
    Views:
    533
    =?Utf-8?B?U3VyZXNo?=
    Mar 2, 2004
  4. Brian K. Williams
    Replies:
    0
    Views:
    549
    Brian K. Williams
    Mar 2, 2004
  5. Andreas Klemt
    Replies:
    0
    Views:
    320
    Andreas Klemt
    Oct 8, 2003
Loading...

Share This Page