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]
Dynamic DataCustom Field TemplatesGridView
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
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)
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 [:(]
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)
{
if (metaCol.GetType().FullName.Contains("MetaChildrenColumn"))
{
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
if (column.ColumnInOtherTable.GetType().FullName.Contains("MetaForeignKeyColumn"))
{
Label label = new Label();
label.Text = column.Name;
count++;
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";
eds.WhereParameters.Add(param);
divExtraTables.Controls.Add(label);
divExtraTables.Controls.Add(eds);
divExtraTables.Controls.Add(gv);
DynamicDataManager1.RegisterControl(gv);
}
}
}
}
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.
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]
Hope this helps [:D]
Dynamic DataCustom Field TemplatesGridView
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
sjnaughton
All-Star
25698 Points
5169 Posts
MVP
Re: Dynamic child details on a dynymic details or edit page?
Aug 08, 2008 07:51 PM|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]
Dynamic Data Custom Field Templates GridView
Always seeking an elegant solution.
zwitterion
Member
46 Points
62 Posts
Re: Dynamic child details on a dynymic details or edit page?
Aug 08, 2008 07:55 PM|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)
sjnaughton
All-Star
25698 Points
5169 Posts
MVP
Re: Dynamic child details on a dynymic details or edit page?
Aug 08, 2008 08:19 PM|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 [:(]
Dynamic Data Custom Field Templates GridView
Always seeking an elegant solution.
sjnaughton
All-Star
25698 Points
5169 Posts
MVP
Re: Dynamic child details on a dynymic details or edit page?
Aug 08, 2008 11:06 PM|LINK
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 GridView.
Dynamic Data Metadata Attributes Custom Field Templates GridView
Always seeking an elegant solution.
zwitterion
Member
46 Points
62 Posts
Re: Dynamic child details on a dynymic details or edit page?
Aug 11, 2008 03:07 PM|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) { if (metaCol.GetType().FullName.Contains("MetaChildrenColumn")) { 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 if (column.ColumnInOtherTable.GetType().FullName.Contains("MetaForeignKeyColumn")) { Label label = new Label(); label.Text = column.Name; count++; 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"; eds.WhereParameters.Add(param); divExtraTables.Controls.Add(label); divExtraTables.Controls.Add(eds); divExtraTables.Controls.Add(gv); DynamicDataManager1.RegisterControl(gv); } } } }sjnaughton
All-Star
25698 Points
5169 Posts
MVP
Re: Dynamic child details on a dynymic details or edit page?
Aug 11, 2008 03:42 PM|LINK
I'm asuming that this solution is via a custom but generic page?
Dynamic Data Custom Pages
Always seeking an elegant solution.
zwitterion
Member
46 Points
62 Posts
Re: Dynamic child details on a dynymic details or edit page?
Aug 11, 2008 04:39 PM|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.
sjnaughton
All-Star
25698 Points
5169 Posts
MVP
Re: Dynamic child details on a dynymic details or edit page?
Aug 11, 2008 04:57 PM|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]
Hope this helps [:D]
Dynamic Data Custom Field Templates GridView
Always seeking an elegant solution.