locked
Dynamic Filter and GridView RRS feed

  • Question

  • User1432255915 posted

    Hi,

    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 company.

    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())
                          select c;

    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.

    namespace MarsUsersAdmin.DAL
    {
        [ScaffoldTable(false)]
        [DisplayColumn("CompanyName", "CompanyName")]
        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:

    namespace MarsUsersAdmin.DAL
    {
        [ScaffoldTable(true)]
        [DisplayName("User")]
        [DisplayColumn("FirstName", "FirstName")]
        public partial class tblUser
        {
          

        }
    }

    This is the LINQ query I need to run:

    from u in users
            where u.tblWorkgroups.Any()
            select u;

    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

    Cheers

    C

     

    Monday, February 6, 2012 7:26 AM

Answers

All replies

  • User1432255915 posted

    Hi,

    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" ?

    How?

    ((System.Web.DynamicData.MetaColumn)(Column)).DisplayName == "tblCompany" true bool

    protected void Page_Init(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    if (!Column.IsRequired)
                    {
                        DropDownList1.Items.Add(new ListItem("[Not Set]", NullValueString));
                    }
                    PopulateListControl(DropDownList1);
                    // Set the initial value if there is one
                    string initialValue = DefaultValue;
                    if (!String.IsNullOrEmpty(initialValue))
                    {
                        DropDownList1.SelectedValue = initialValue;
                    }
                }
            }

    Cheers

    C

    Monday, February 6, 2012 11:47 AM
  • User-330204900 posted

    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

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 7, 2012 12:48 PM