Last post Aug 11, 2008 12:57 PM by sjnaughton
Mar 18, 2008 12:34 AM|txghia58|LINK
I was wondering if it was possible to have multiple details sections in the edit or details page.
For example the Clients table has foriegn keys pointing to it from Orders and Calls.
So when I am on the Edit client page it would be nice if at the bottom there was 2 tabs one showing the Orders of the client and one showing the calls of the client.
Mar 18, 2008 01:58 PM|aldion|LINK
It's possible, but do you mean to have two list for the multiple orders and calls for each client ?
I wrote this little example that list all the Orders in the botom of the Edit view for a Customer using the Northwind database.
Mar 20, 2008 11:06 AM|txghia58|LINK
Actualy I was wanting it to use the Dynamic Data.
Have it automaticaly generate the different data grids based on the foriegn keys that are in the datacontext Instead of having to create a seperate page for each table in the system
Companies have Contact, Orders, Calls, etc..
Contacts have Orders, Calls etc....
Orders have Order Items, Calls, Shipping Details etc....
Calls have Call Details etc...
This is a real basic layout I am showing here other wise I would just create a pages for each item.
Mar 21, 2008 06:00 PM|aldion|LINK
I generalized the previous example by adding this portion of code in the page_load in the codebehind. It just add a Gridview with the values of all the children columns...
Mar 21, 2008 10:58 PM|txghia58|LINK
Yes that sure does solve it.
Aug 07, 2008 03:53 PM|zwitterion|LINK
Hi your solution works great but only when the navigation property on the 'child' table is named the same as the 'parent' table. What's the best way to determine the name of the navigation property on the related end of an association - for instance if I
then your code will not work because it assumes that the sub table's entity set name is 'children', and that the sub table's related column is 'node' - neither of which is true. The sub table's entity set is actually 'node' and its related column is 'parent',
but I don't know how to best to programmatically determine this.
Aug 07, 2008 05:51 PM|sjnaughton|LINK
Also have alook at this post on my blog it may be of some use here also:
An Advanced FieldTemplate with a GridView.
Hope this helps [:D]
Custom Field Templates
Aug 08, 2008 02:31 PM|zwitterion|LINK
Aug 08, 2008 02:48 PM|sjnaughton|LINK
your field template example makes assumptions about FK naming conventions which my association abstractions render problematic (specifically, I can't assume that the FK on the child table is going to be the same name as the PK on the parent, for reasons like
single table hierarchies).
Sorry I don't understand where I'm making any asumptions about FK PK naming I reading the PK's from the
ChildTable.PrimaryKeyColumns so the names of the keys come from the metadata of the child table.
Could you be more specific as I would like to make this as generic as possible [:D]
Aug 08, 2008 03:40 PM|zwitterion|LINK
sure. because i'm using EF i made a slight change to the datasource set up (it's an entitydatasource now in my app) so,
GridDataSource.EntitySetName = column.ChildTable.Name;
// setup the where clauseString value = Request.QueryString;String name = Request.QueryString.AllKeys;var fkColumn = table.GetColumn(name);var param = new Parameter();param.Name = name;// set the data type of the where parameterparam.Type = Type.GetTypeCode(fkColumn.ColumnType);param.DefaultValue = value;// add the where clauseGridDataSource.WhereParameters.Add(param);
So if I read this right, if i go to /Nodes/Edit.aspx?id=1 (using my above exmple) then this will loadup "id" into "fkColumn" with the value of 1. And given that my child table is the same table (or entityset) as the parent, I'm just going to get a gridview
in the Children column showing me the record i'm looking at anyway.
I suppose I need a way of determining, from the MetaChildrenColumn, what the corresponding navigation property on the other side of the association is, and use THAT as the column name.
Aug 08, 2008 03:51 PM|sjnaughton|LINK
Yes I see what you mean the Key passed into the page is the key of the parent tavble not the child table I think I will add this as Metadata i will update my article apprpriatly and post here when its done [:D]
Thanks a gain for spotting this [:D]
Aug 08, 2008 03:55 PM|zwitterion|LINK
np. If you can think of a way of determining it using the EF rather than just adding it to metadata, post that too cos I'm stumped :( (and you'd think it'd be easy)
Aug 08, 2008 04:19 PM|sjnaughton|LINK
I've done and tested the Attribute and have posted it. [:D]
I can't see a way to determin it via Column.ChildTable's metadata sorry [:(]
Aug 08, 2008 07:06 PM|sjnaughton|LINK
If you can think of a way of determining it using the EF rather than just adding it to metadata, post that too cos I'm stumped :( (and you'd think it'd be easy)
I've found this in the metadata metaChildColumn.ChildTable.ForeignKeyColumnsNames
contains "Order,Product" in the Order->Order_Details of the Northwind DB. As you can see below it shows the tables NOT the columns and not the relationship [:(]
Hope this helps [:D]
I think you will need to add the metadata see the updated post on my blog:
Part 5 an Advanced FieldTemplate with a
Custom Field Templates
Aug 11, 2008 11:07 AM|zwitterion|LINK
ok it IS possible and I just wasted half a week due to not seeing the very obvious property that was right in front of my eyes. Here's what I'm using right now.
protected void Page_Load(object sender, EventArgs e)
table = DetailsDataSource.GetTable();
Title = table.DisplayName;
ListHyperLink.NavigateUrl = table.ListActionPath;
int count = 0;
foreach (MetaColumn metaCol in table.Columns)
var column = metaCol as MetaChildrenColumn;
//The columnInOtherTable can be a metachildrencolumn too in the case of m:n relationships, but that doesn't work with this approach
Label label = new Label();
label.Text = column.Name;
GridView gv = new GridView();
gv.DataSourceID = "DataSource" + count;
gv.ID = "myGV" + count;
gv.AllowPaging = true;
EntityDataSource eds = new EntityDataSource();
eds.ID = "DataSource" + count;
eds.ContextTypeName = "myEntityContainerType";
eds.EntitySetName = column.ColumnType.Name;
DynamicControlParameter param = new DynamicControlParameter();
param.Name = column.ColumnInOtherTable.Name;
param.ControlId = "DetailsView1";
Aug 11, 2008 11:42 AM|sjnaughton|LINK
I'm asuming that this solution is via a custom but generic page?
Aug 11, 2008 12:39 PM|zwitterion|LINK
Yes that's my rewrite of the PageTemplates/Details.aspx.cs Page_Load. It is simply aldion's solution redone to work with the entity framework and arbitrary relationship names.
The next challenge is many-to-many relationships which it seems DD does not have good support for yet.
Aug 11, 2008 12:57 PM|sjnaughton|LINK
Hi Zwitterion, just for your information and thanks for the nudge with the
Column.ColumnInOtherTable I've updated my
An Advanced FieldTemplate with a GridView to take advantage of your nugget of Gold, even if it did take you a week to spot it, thanks [:D] And now it supports Clustered/Composite Key columns.
[:D] and no need for that extra metadata noiw either [:D]