Nest Datagrids

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2004
Posts: 6
Reputation: daniel75 is an unknown quantity at this point 
Solved Threads: 0
daniel75 daniel75 is offline Offline
Newbie Poster

Nest Datagrids

 
0
  #1
May 5th, 2004
I have a datagrid show all "New" work orders. I want to be able to open "History" of a work order under that work order number in the same datagrid. How would I do that? Do I need to insert rows or is it possible to insert a datagrid under that row? Note: I do not want the datagrid inside one field, I want it to have the same fields as the datagrid, but under the current row (and before next "New" row). Do I need to use datalist or repeater?

Hope someone can help me.
Thanks!
/Daniel
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 634
Reputation: Slade has a spectacular aura about Slade has a spectacular aura about 
Solved Threads: 7
Slade's Avatar
Slade Slade is offline Offline
Practically a Master Poster

Re: Nest Datagrids

 
0
  #2
May 5th, 2004
I wish I could help dude, I am waiting for someone to answer my questions too. Just be patient and one of the moderators will get to you .
Formerly known as Slade.
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 4
Reputation: plope is an unknown quantity at this point 
Solved Threads: 0
plope's Avatar
plope plope is offline Offline
Newbie Poster

Re: Nest Datagrids

 
0
  #3
May 21st, 2004
You can use two datagrids. You will need to use the HTML view to add the second datagrid in a templated column of the first datagrid. Then you have to add a sub for the ItemDataBound of the parent grid.

Inside the ItemDataBound routine, you will need to check each row and then filter a dataset on that item number and bind those results to the child datagrid.

Since you are new to ASP.NET, I will work up a sample and submit it here. Hopefully, that will get you started for now.
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 4
Reputation: plope is an unknown quantity at this point 
Solved Threads: 0
plope's Avatar
plope plope is offline Offline
Newbie Poster

Re: Nest Datagrids

 
0
  #4
May 21st, 2004
Here's how your datagrid might look:

  1.  
  2. <asp:DataGrid id="dgParent" runat="server" AutoGenerateColumns="False" OnItemDataBound="DataBound">
  3. <Columns>
  4. <asp:BoundColumn DataField="ID" HeaderText="ID"></asp:BoundColumn>
  5. <asp:TemplateColumn HeaderText="Detail">
  6. <ItemTemplate>
  7. <asp:DataGrid id="dgChild" runat="server" AutoGenerateColumns="False">
  8. <Columns>
  9. <asp:BoundColumn DataField="ID" HeaderText="ID"></asp:BoundColumn>
  10. <asp:BoundColumn DataField="Desc" HeaderText="Desc"></asp:BoundColumn>
  11. </Columns>
  12. </asp:DataGrid>
  13. </ItemTemplate>
  14. </asp:TemplateColumn>
  15. </Columns>
  16. </asp:DataGrid>

(And I acutally did do this in the Property Builder while editing the templated column in dgParent).

And then your code would look something like this:

  1. Private Shared ds As DataSet
  2.  
  3. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4. If Not Page.IsPostBack Then
  5. BindData()
  6. End If
  7. End Sub
  8.  
  9. Private Sub BindData()
  10. 'build your dataset here (from database or manually or whatever)
  11. Dim tbl As New DataTable("Parent")
  12. tbl.Columns.Add("ID", GetType(Integer))
  13. tbl.Columns.Add("Desc", GetType(String))
  14.  
  15. Dim tblChild As New DataTable("Child")
  16. With tblChild.Columns
  17. .Add("ID", GetType(Integer))
  18. .Add("Desc", GetType(String))
  19. End With
  20.  
  21. Dim row, chRow As DataRow
  22. Dim i, j As Short
  23.  
  24. For i = 1 To 10
  25. row = tbl.NewRow()
  26. row("ID") = i
  27. row("Desc") = "Parent row " & i
  28. For j = 1 To 2
  29. chRow = tblChild.NewRow()
  30. chRow("ID") = i
  31. chRow("Desc") = "Child row " & j
  32. tblChild.Rows.Add(chRow)
  33. Next
  34. tbl.Rows.Add(row)
  35. Next
  36.  
  37. ds = New DataSet("ParentChild")
  38. ds.Tables.Add(tbl)
  39. ds.Tables.Add(tblChild)
  40.  
  41. 'don't have to do this, but might be helpful
  42. ds.Relations.Add("relationID", ds.Tables(0).Columns("ID"), ds.Tables(1).Columns("ID"))
  43.  
  44. dgParent.DataSource = ds.Tables(0)
  45. dgParent.DataBind()
  46. End Sub
  47.  
  48. Public Sub DataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgParent.ItemDataBound
  49. If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
  50. Dim id As Integer = DataBinder.Eval(e.Item.DataItem, "ID")
  51. Dim childView As New DataView(ds.Tables(1))
  52. childView.RowFilter = "ID = " & id
  53.  
  54. Dim dgChild As DataGrid = e.Item.FindControl("dgChild")
  55. dgChild.DataSource = childView
  56. dgChild.DataBind()
  57. End If
  58. End Sub
  59.  
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 4
Reputation: plope is an unknown quantity at this point 
Solved Threads: 0
plope's Avatar
plope plope is offline Offline
Newbie Poster

Re: Nest Datagrids

 
0
  #5
May 21st, 2004
I just re-read your reply and realized you did not want the "History" in a field of the "New" datagrid. So I would say your best bet would be to use a datalist or repeater. Your steps would be essentially the same with the filter of the "History" data in the ItemDataBound routine.

Hope that helps!
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 8
Reputation: siddartha_pal is an unknown quantity at this point 
Solved Threads: 0
siddartha_pal siddartha_pal is offline Offline
Newbie Poster

Re: Nest Datagrids

 
0
  #6
Jul 20th, 2004
Originally Posted by daniel75
I have a datagrid show all "New" work orders. I want to be able to open "History" of a work order under that work order number in the same datagrid. How would I do that? Do I need to insert rows or is it possible to insert a datagrid under that row? Note: I do not want the datagrid inside one field, I want it to have the same fields as the datagrid, but under the current row (and before next "New" row). Do I need to use datalist or repeater?

Hope someone can help me.
Thanks!
/Daniel
Hi

culd u pls provide more info on the same,solution will be based on how ur page to look like

thsnks n rgards
siddartha
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 898
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Solved Threads: 28
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: Nest Datagrids

 
0
  #7
Jul 20th, 2004
Sorry about not noticing your thread earlier . Sometimes, its hard to describe what you want to do, and if you can't describe what you want, you can't find help for it. I'm pretty sure what you are trying to do is build a Master/Detail Nested Datagrid.

Check out this article on DotNetJunkies: Building a Master/Detail DataGrid, and after you're through with that, check out Building a Master/Detail DataGrid Part II .
-Ryan Hoffman

.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 1
Reputation: Moistly is an unknown quantity at this point 
Solved Threads: 0
Moistly Moistly is offline Offline
Newbie Poster

Re: Nest Datagrids

 
0
  #8
Nov 16th, 2004
I too have been having trouble with this problem.

The difficulty seems to lie with

Note: I do not want the datagrid inside one field, I want it to have the same fields as the datagrid, but under the current row (and before next "New" row).
All I can find are examples that add a datagrid/ datalist/ repeater to a <asp:TemplateColumn> but that is not what is required here. Has anybody got any ideas?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1
Reputation: hlesesne is an unknown quantity at this point 
Solved Threads: 0
hlesesne hlesesne is offline Offline
Newbie Poster

Re: Nest Datagrids

 
0
  #9
Dec 13th, 2004
I don't know if you have taken a look at Denis Bauer site and blog, but he has available his source code (as well as a compiled assembly) for Heirargrid...

[RIGHT HERE]

It is nicely done and having the source makes tailoring to fit a piece of cake...

Thanks,

Hal
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Nest Datagrids

 
0
  #10
Dec 13th, 2004
What would trigger the action? Yes, you can add new rows. What are you binding to the DataGrid?

I like to use a DataReader, as they are very high performance. I loop through the DataReader to create an ArrayList. Then I bind the ArrayList to the DataGrid.

In server-side code, it is easy to add items to the ArrayList and simply re-bind.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC