Click here to Skip to main content
15,908,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,


have a form with 2 gridviews.

one gridview is for the parent and the other gridview is for the transaction of the selected master record.



How do you link the tables such that on selection of a record from the master gridview it will populate the child gridview with details of only the transactions of the selected master details.


Assuming the master table has the following details idno, name , age.

and the child has the following idno, name , transaction_date, amount


How do you link the 2 tables to populate their repective gridviews

I have built the various gridviews and they are all being populated with the entire records in

each table.

I need to now do the ink.


Please assist or any reference will be acceptable


Thanks


.
Posted

Not sure if you are using Windows Forms or ASP.net, but if you are using Forms you should use the class BindingSource.

BindingSource Class[^]

If you have a DataSet, dsExample, with two data tables, MasterTable and ChildTable, which have a parent child relation named MasterTable_ChildTable, you create two binding sources.
C#
// You don't usually do these steps manually, but in the property grid
// for each BindingSource in Visual Studio.
// Then you will get a dropdown list for each property.
// This is just to show the principle.
BindingSource bsMaster = new BindingSource();
bsMaster.DataSource = dsExample;
bsMaster.DataMember = "MasterTable";

BindingSource bsChild = new BindingSource();
bsChild.DataSource = bsMaster;
bsChild.DataMember = "MasterTable_ChildTable";

dataGridMaster.DataSource = bsMaster;
dataGridChild.DataSource = bsChild;

Now the values in your datagrid with child data should change when you change rows in the master grid.

I hope this will help you on the way.
 
Share this answer
 
Comments
Member 10744248 4-Sep-14 23:20pm    
using asp.net

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900