473,758 Members | 5,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Master/Detail

Good Day Folks,

I found the following code here on MSDN illustrating
master/detail.

You can see the original at the following URL.

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpref/html/frlrfsystemdata datatableclasst opic.asp

It doesn't seem to do anything other than display the
master table. Does anyone know how to make this sample
work correctly ?

Thanks in advance
/Serge

<%@ Page Explicit="True" AutoEventWireup ="True"
Language="VB" Debug="true"%>
<%@ Import Namespace="Syst em" %>
<%@ Import Namespace="Syst em.Data" %>
<html>
<head>
<title>Master Detail</title>
</head>

<script language="VB" runat="server">

private myDataSet As DataSet

Sub Page_Load(sende r As Object, e As EventArgs)

MakeDataTables( )

End Sub
Private Sub MakeDataTables( )
' Run all of the functions.
MakeParentTable ()
MakeChildTable( )
MakeDataRelatio n()
BindToDataGrid( )
End Sub

Private Sub MakeParentTable ()
' Create a new DataTable.
Dim myDataTable As DataTable = new DataTable
("ParentTabl e")
' Declare variables for DataColumn and DataRow objects.
Dim myDataColumn As DataColumn
Dim myDataRow As DataRow

' Create new DataColumn, set DataType, ColumnName and
add to DataTable.
myDataColumn = New DataColumn()
myDataColumn.Da taType = System.Type.Get Type
("System.Int32" )
myDataColumn.Co lumnName = "id"
myDataColumn.Re adOnly = True
myDataColumn.Un ique = True
' Add the Column to the DataColumnColle ction.
myDataTable.Col umns.Add(myData Column)

' Create second column.
myDataColumn = New DataColumn()
myDataColumn.Da taType = System.Type.Get Type
("System.String ")
myDataColumn.Co lumnName = "ParentItem "
myDataColumn.Au toIncrement = False
myDataColumn.Ca ption = "ParentItem "
myDataColumn.Re adOnly = False
myDataColumn.Un ique = False
' Add the column to the table.
myDataTable.Col umns.Add(myData Column)

' Make the ID column the primary key column.
Dim PrimaryKeyColum ns(0) As DataColumn
PrimaryKeyColum ns(0)= myDataTable.Col umns("id")
myDataTable.Pri maryKey = PrimaryKeyColum ns

' Instantiate the DataSet variable.
myDataSet = New DataSet()
' Add the new DataTable to the DataSet.
myDataSet.Table s.Add(myDataTab le)

' Create three new DataRow objects and add them to the
DataTable
Dim i As Integer
For i = 0 to 2
myDataRow = myDataTable.New Row()
myDataRow("id") = i
myDataRow("Pare ntItem") = "ParentItem " + i.ToString
()
myDataTable.Row s.Add(myDataRow )
Next i
End Sub

Private Sub MakeChildTable( )
' Create a new DataTable.
Dim myDataTable As DataTable = New DataTable
("childTable ")
Dim myDataColumn As DataColumn
Dim myDataRow As DataRow

' Create first column and add to the DataTable.
myDataColumn = New DataColumn()
myDataColumn.Da taType= System.Type.Get Type
("System.Int32" )
myDataColumn.Co lumnName = "ChildID"
myDataColumn.Au toIncrement = True
myDataColumn.Ca ption = "ID"
myDataColumn.Re adOnly = True
myDataColumn.Un ique = True
' Add the column to the DataColumnColle ction.
myDataTable.Col umns.Add(myData Column)

' Create second column.
myDataColumn = New DataColumn()
myDataColumn.Da taType= System.Type.Get Type
("System.String ")
myDataColumn.Co lumnName = "ChildItem"
myDataColumn.Au toIncrement = False
myDataColumn.Ca ption = "ChildItem"
myDataColumn.Re adOnly = False
myDataColumn.Un ique = False
myDataTable.Col umns.Add(myData Column)

' Create third column.
myDataColumn = New DataColumn()
myDataColumn.Da taType= System.Type.Get Type
("System.Int32" )
myDataColumn.Co lumnName = "ParentID"
myDataColumn.Au toIncrement = False
myDataColumn.Ca ption = "ParentID"
myDataColumn.Re adOnly = False
myDataColumn.Un ique = False
myDataTable.Col umns.Add(myData Column)

myDataSet.Table s.Add(myDataTab le)
' Create three sets of DataRow objects, five rows
each, and add to DataTable.
Dim i As Integer
For i = 0 to 4
myDataRow = myDataTable.New Row()
myDataRow("chil dID") = i
myDataRow("Chil dItem") = "Item " + i.ToString()
myDataRow("Pare ntID") = 0
myDataTable.Row s.Add(myDataRow )
Next i
For i = 0 to 4
myDataRow = myDataTable.New Row()
myDataRow("chil dID") = i + 5
myDataRow("Chil dItem") = "Item " + i.ToString()
myDataRow("Pare ntID") = 1
myDataTable.Row s.Add(myDataRow )
Next i
For i = 0 to 4
myDataRow = myDataTable.New Row()
myDataRow("chil dID") = i + 10
myDataRow("Chil dItem") = "Item " + i.ToString()
myDataRow("Pare ntID") = 2
myDataTable.Row s.Add(myDataRow )
Next i
End Sub

Private Sub MakeDataRelatio n()
' DataRelation requires two DataColumn (parent and
child) and a name.
Dim myDataRelation As DataRelation
Dim parentColumn As DataColumn
Dim childColumn As DataColumn
parentColumn = myDataSet.Table s("ParentTable" ).Columns
("id")
childColumn = myDataSet.Table s("ChildTable") .Columns
("ParentID")
myDataRelation = new DataRelation("p arent2Child",
parentColumn, childColumn)
myDataSet.Table s("ChildTable") .ParentRelation s.Add
(myDataRelation )
End Sub

Private Sub BindToDataGrid( )
' Instruct the DataGrid to bind to the DataSet, with
the
' ParentTable as the topmost DataTable.
'DataGrid1.SetD ataBinding(myDa taSet,"ParentTa ble")
DataGrid1.DataS ource=myDataSet
DataGrid1.DataM ember="ParentTa ble"
DataGrid1.DataB ind()
End Sub

</script>

<body text="black" bgcolor="" link="blue" vlink="blue"
alink="blue" leftmargin="0" topmargin="0" marginheight="0 "
marginwidth="0" >

<center><font size="+2">Maste r/Detail</font></center>

<form id="MasterDetai l" runat="server">

<asp:DataGrid id="DataGrid1" runat="server" />

</form>

</body>
</html>
Nov 17 '05 #1
0 1068

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1467
by: Marcel | last post by:
Hi, I'm new to VS and ASP.NET and have a question about master/detail datagrids. I have a master datagrid filled with data via a component that contains a SQL adapter. Now I would like to fill a detail datagrid (which will contain a number of detail records) based on the selected master. Is it possible to
2
423
by: ruca | last post by:
Hi, I have a master and a detail datagrid. I put detail grid showing insise of a column of master grid. The problem is that it's not what I really want. What I really want would be that the detail grid appears between rows of master grid, i.e., when I select one record in master grid that detail grid appears between the selected row and next row. I know that the reason why my detail grid is show in one master column it's because I...
2
1997
by: Ken C | last post by:
I've setup a Master detail table from a typed dataset on 2 different data grid The first one I bind it with the Master data table name The second data set I bind it with the MasterDetail Relation name so that I can obtain a "Detail Auto change" effect when current master record is moving around, which is suggested on syncfusion FA http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q780 But the problem is when I try to update a new...
2
1376
by: Coen | last post by:
Hello, I have a strange performance delay of about 2 sec's in moving to the next row. I use multiple forms with each master-detail table relations. The master-table displays it's table rows in databound textboxes, the detail tables in datagrids, and of course relations defined between the master and detail tables. All the tables are part of one dataset (per form). The following happens. When moving to the next tablerow (next record) I...
1
2183
by: Sam | last post by:
Attached I am sending 2 URL's from MSFT ASP.net Quick Start Tutorial Web Site. 1) Run it URL: http://www.asp.net/QuickStart/aspnet/samples/data/GridViewMasterDetai... 2) View Source URL: http://www.asp.net/QuickStart/util/srcview.aspx?path=~/aspnet/samples...
0
1301
by: Sam | last post by:
Sorry to post the same post multiple times but the URL Addresses were not Correct in Earlier Posts. Here are the correct URL's: 1) Run It URL is here: http://www.asp.net/QuickStart/aspnet/samples/data/GridViewMasterDetailsInsertPage_vb.aspx
1
1529
by: Gary200 | last post by:
Hello All, I bind two datagrids in a master-detail relationship successfully. What I want is to set allowNew and allowDelete disabled in both datagrid using dataview. The code like this: Dim masterGrid As DataGrid Dim detailGrid As DataGrid
7
4539
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent records. Should I design a new form for this or can I somehow make this work in the same form. Thanks in advance, john
0
1726
by: Mike Wilson | last post by:
Dear group, I have an invoice entry form, which is a simple Master fields / Detail grid. The main summary information of the invoice are stored in one table in a dataset, which is bound using a BindingSource (InvoiceBindingSource). The line details of each item in the invoice is held in a child table which is bound to another bindingsource (InvoiceRowsBindingSource). I took the basic design from an MSDN article, and all works well....
2
2286
by: John | last post by:
Hi I am trying to create a master/detail form. I have my master and details tables dragged onto the dataset. I have also dragged the fields from master table on the form which has created the navigation toolbar for me and which works fine with the master table. I also have a dataview on the same form ready for detail table but as yet not assigned to the detail table. How can I now create a master/detail relationship between my master and...
0
10072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.