ASP.net - Parent, Child and relationships

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
Just started out in ASP.net, all my previous work was in VB.net.

I may have got the wrong idea here, but hopefully someone can clear this up for me!!!

I know how to do a master-detail view. It shows the child rows based on the parent row selected.

HOWEVER......

How (in ASP.net) do I show related data??? I posted a thread about taking a parameter from a grid column but didn't really get an answer.

What I mean is that in my PARENT table, I have it's PK, but also 2 FK's related to 2 other tables.

Now, when the parent row is selected, I want 2 other grids to show the details of those 2 FKs.

I.E. I have a "XYZ". A XYZ is created by filling in some information and selecting BOTH a "Recipe" and a "Sieve".

Now the parent table (XYZ) will show this as (example) ;

XYZ_ID: 1
Description: Example
DateCreated: 03/05/07
CreatedBy: arg81
RecipeID: 10
SieveID: 7


So I can get a grid to show the above. I then want a grid to show the RecipeID details for RecipeID 1 and another grid to show the SieveID details for SieveID 7.


As the user browses through the XYZ rows, these 2 grids should change accordingly to the correct value shown in the XYZ grid.


Easy to do in a VB windows application but I'm completely lost in trying to do it in ASP.net !!! There are reasons I need to do it this way and can't do is as a windows application, otherwise I would of done to start with!!

If anyone can help, or at least point me in the correct direction I would be very grateful!!

Regards,



EDIT
Just had a thought, and I can obviously make a dataTable in the dataSet that contains all the rows I need to display, and then get this form to show one grid with everything in. (In fact I could probably split it across a few grids by using visible=False on certain columns in each grid). By doing this I would lose my UPDATE queries. I would still need to update the parent table (in case the wrong sieve was selected for example), so what would be the best way of getting around this?
 
Last edited:
Thanks Paszt, they are the tutorials I'm already using.

However I can't see it working in this scenario. My main table has the FK-ID (i.e. 1), but i then want a second grid to show the row where the ID is 1.

It is a master-child detail view, but it's the other way round in a sense - my scenario is the "master" is the PK table and the "child" is the main table with the FK :)

Thanks anyway, I think I've found a way around it, just playing about at the mo.
 
Here's a screenshot of my relationship to try and make this easier.

I'm not sure why it's such a difficult task. DC is my main table and 1 DC can only have 1 recipe and 1 sieve, but that recipe or sieve can be used in many DC's.
Therefore it's a standard 1-to-many relationship, except I'm trying to use the FK's (RecipeID, SieveTypeID) from the DC table to load child grids, and not the FK from the child table....
 

Attachments

  • Image2.jpg
    Image2.jpg
    104.6 KB · Views: 26
I would of thought I could show a table based on it's relation? So if I have a grid setup to DC_Sieve relation, then if the DC grid shows SieveTypeID = 1, then the Sieve grid will look at the relation and then only show the details for SieveTypeID 1 ????

If I find anything that works, I'll post it as it'll no doubt come in handy for anyone else who finds themselves in a situation like this!!

EDIT
The only way I've found of doing this so far, is to create the SQL code to include the related columns. Then split the data down into multiple grids. This is more workload, as I then need to create extra DataTables for doing this, create extra BLL code, and create extra forms for Editing/Inserting.


Surely there's a simplier way!
 
Last edited:
I've read this several times and am really unsure of what you're trying to accomplish. You say 1 DC can only have 1 recipe and 1 sieve but then you say you want to use the FK's (RecipeID, SieveTypeID) from the DC table to load child grids. Would the child grids then only show 1 row each?
Or do you mean to have a details view to show the child records?
Perhaps if you made a mock-up of the required results that would help others understand.
 
Hi Paszt, sorry should of put some mock data on the post to start with!!

OK, as you can see from the screenshot, the DC table has recipeID and sievetypeID. These are related to "lookup" tables in essence.

Yes, one DC can only have the 1 recipeID and 1 sieveTypeID. - DCNumber is an Identity so the same DCNumber isn't used more than once.

You've got it in one - I want the child grids to only show 1 row. The row where the recipeID or sievetypeID is that which is shown in the DC grid.

I've attached a screenshot of a form - although when I get it working I'll probably be loading 1 DC at a time, instead of them all appearing in a grid. In this example, when the user presses Select on a row, it loads the correct detailsView information - the recipe detailsView will show the record where RecipeID = DC.RecipeID and the sieve detailsView will show the record where SieveTypeID = DC.SieveTypeID.

Does that make any more sense ?

Thanks for the help so far.

EDIT - I think I realised where I made the confusion. I was talking about grids for the child data when in fact I really meant detailsView. Sorry!!!!!
 

Attachments

  • Image2.jpg
    Image2.jpg
    61.1 KB · Views: 22
Last edited:
Back
Top