| | |
Nest Datagrids
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2004
Posts: 6
Reputation:
Solved Threads: 0
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
Hope someone can help me.
Thanks!
/Daniel
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.
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.
Here's how your datagrid might look:
(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)
<asp:DataGrid id="dgParent" runat="server" AutoGenerateColumns="False" OnItemDataBound="DataBound"> <Columns> <asp:BoundColumn DataField="ID" HeaderText="ID"></asp:BoundColumn> <asp:TemplateColumn HeaderText="Detail"> <ItemTemplate> <asp:DataGrid id="dgChild" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundColumn DataField="ID" HeaderText="ID"></asp:BoundColumn> <asp:BoundColumn DataField="Desc" HeaderText="Desc"></asp:BoundColumn> </Columns> </asp:DataGrid> </ItemTemplate> </asp:TemplateColumn> </Columns> </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)
Private Shared ds As DataSet Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then BindData() End If End Sub Private Sub BindData() 'build your dataset here (from database or manually or whatever) Dim tbl As New DataTable("Parent") tbl.Columns.Add("ID", GetType(Integer)) tbl.Columns.Add("Desc", GetType(String)) Dim tblChild As New DataTable("Child") With tblChild.Columns .Add("ID", GetType(Integer)) .Add("Desc", GetType(String)) End With Dim row, chRow As DataRow Dim i, j As Short For i = 1 To 10 row = tbl.NewRow() row("ID") = i row("Desc") = "Parent row " & i For j = 1 To 2 chRow = tblChild.NewRow() chRow("ID") = i chRow("Desc") = "Child row " & j tblChild.Rows.Add(chRow) Next tbl.Rows.Add(row) Next ds = New DataSet("ParentChild") ds.Tables.Add(tbl) ds.Tables.Add(tblChild) 'don't have to do this, but might be helpful ds.Relations.Add("relationID", ds.Tables(0).Columns("ID"), ds.Tables(1).Columns("ID")) dgParent.DataSource = ds.Tables(0) dgParent.DataBind() End Sub Public Sub DataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgParent.ItemDataBound If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then Dim id As Integer = DataBinder.Eval(e.Item.DataItem, "ID") Dim childView As New DataView(ds.Tables(1)) childView.RowFilter = "ID = " & id Dim dgChild As DataGrid = e.Item.FindControl("dgChild") dgChild.DataSource = childView dgChild.DataBind() End If End Sub
•
•
Join Date: Jun 2004
Posts: 8
Reputation:
Solved Threads: 0
•
•
•
•
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
culd u pls provide more info on the same,solution will be based on how ur page to look like
thsnks n rgards
siddartha
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
.
. 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.
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
•
•
Join Date: Nov 2004
Posts: 1
Reputation:
Solved Threads: 0
I too have been having trouble with this problem.
The difficulty seems to lie with
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?
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).
•
•
Join Date: Dec 2004
Posts: 1
Reputation:
Solved Threads: 0
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
[RIGHT HERE]
It is nicely done and having the source makes tailoring to fit a piece of cake...
Thanks,
Hal
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
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.
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.
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: TextBox - how to determine focus
- Next Thread: .NET framework FAX library
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances asp asp.net beginner box browser businesslogiclayer button c# c#gridviewcolumn cac checkbox class compatible confirmationcodegeneration content contenttype countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv forms gridview gudi homeedition iis javascript jquery list listbox menu microsoft mouse mssql nameisnotdeclared news novell numerical opera order panelmasterpagebuttoncontrols problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server ssl tracking treeview validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming webservice xml xsl






. 