Last post Feb 07, 2012 12:48 PM by sjnaughton
Feb 06, 2012 07:26 AM|pallone|LINK
I am scaffolding only one table to my DD web application - tblUser
This table has a lot of foreign navigation properties. Ex. tblUser-------->tblCompany (one company has many users)
I get a gridview with all the fields from tblUser and the navigation field and a
drop down list box with the companies to filter the gridview by
However, since the drop down list is being populated dynamically, it is bringing more data than it should.
I need to run this LINQ query to further filter the list of companies that shows in the drop down list box filter
from c in companies
where c.tblWorkgroups.Where(wg1 => wg1.tblCompany.CompanyName != "")
.OrderBy(wg2 => wg2.tblCompany.CompanyName)
.Any(wg => wg.tblUsers.Any())
I have created a partial company class to futher filter the list companies to be delivered to the DD site but I am not what method or event to override.
public partial class tblCompany
1 - Can I do that in the partial class?
I think that in the partial class would be the best place because all the pages in the DD site that uses this company collection would benefit from it.
2 - If it is not possible to do that in the partial class, where can I do it in code behind?
I have to do something similar to the users collection and have also created a partial class for that:
public partial class tblUser
This is the LINQ query I need to run:
from u in users
Where is the best place to add this?
I think I have to understand where to futher compose the LINQ queries when using Dynamic Data Web applications
Feb 06, 2012 11:47 AM|pallone|LINK
Since nobody has replied to my question above, I have decided to clarify furhter what I need to achieve.#
My List.aspx page display a gridView and 3 drop drown list boxes. One of the list boxes contains companies to filter the grid by company name.
However, this list is being populated with too many entries because in my database I have empty values and repeat values for company type.
So I need to further filter this list before the drop down list is populated. I was debugging and realised that the ForeignKey.ascx.cs file is called to populate all the dropdown list boxes.
It is posible to hook into this event or use the PopulateListControl method and use composition to filter the companies returned by only doing this when the DisplayName = "tblCompany" ?
((System.Web.DynamicData.MetaColumn)(Column)).DisplayName == "tblCompany" true bool
protected void Page_Init(object sender, EventArgs e)
DropDownList1.Items.Add(new ListItem("[Not Set]", NullValueString));
// Set the initial value if there is one
string initialValue = DefaultValue;
DropDownList1.SelectedValue = initialValue;
Feb 07, 2012 12:48 PM|sjnaughton|LINK
Yes you can I have some sample code on my blog but it is a log of Linq Expressions you can have a look here
Cascading or Dependant Field Templates for ASP.Net 4.0 Preview see particularly my implementation of PopulateListControl