943,846 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 13322
  • ASP.NET RSS
May 5th, 2004
0

Nest Datagrids

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
daniel75 is offline Offline
6 posts
since May 2004
May 5th, 2004
0

Re: Nest Datagrids

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 .
Reputation Points: 115
Solved Threads: 7
Practically a Master Poster
Slade is offline Offline
633 posts
since Mar 2004
May 21st, 2004
0

Re: Nest Datagrids

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
plope is offline Offline
4 posts
since May 2004
May 21st, 2004
0

Re: Nest Datagrids

Here's how your datagrid might look:

ASP.NET Syntax (Toggle Plain Text)
  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:

ASP.NET Syntax (Toggle Plain Text)
  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.  
Reputation Points: 10
Solved Threads: 0
Newbie Poster
plope is offline Offline
4 posts
since May 2004
May 21st, 2004
0

Re: Nest Datagrids

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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
plope is offline Offline
4 posts
since May 2004
Jul 20th, 2004
0

Re: Nest Datagrids

Quote 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
Reputation Points: 11
Solved Threads: 0
Newbie Poster
siddartha_pal is offline Offline
8 posts
since Jun 2004
Jul 20th, 2004
0

Re: Nest Datagrids

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 .
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Nov 16th, 2004
0

Re: Nest Datagrids

I too have been having trouble with this problem.

The difficulty seems to lie with

Quote ...
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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Moistly is offline Offline
1 posts
since Nov 2004
Dec 13th, 2004
0

Re: Nest Datagrids

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hlesesne is offline Offline
1 posts
since Dec 2004
Dec 13th, 2004
0

Re: Nest Datagrids

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.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: How can i change a picture navigation link after succesfuuly logging in.
Next Thread in ASP.NET Forum Timeline: .NET framework FAX library





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC