Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1096381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:16:36+00:00 2026-05-17T00:16:36+00:00

I’m working with ASP.NET 3.5 SP1 and I have a question that I’ve been

  • 0

I’m working with ASP.NET 3.5 SP1 and I have a question that I’ve been stuck on.
I have an ASPX page on which I have 2 repeater controls, 1 nested inside the other.
From the code behind I have a simple LINQ To Entities query which retrieves the data and I then bind this data to the repeater controls.
The ASPX page is shown below:

<asp:Repeater ID="rptrMain" runat="server">
    <ItemTemplate>
        <asp:Label ID="lblName" runat="server"  ></asp:Label>
        <asp:Label ID="lblDescription" runat="server"></asp:Label>                 
        <asp:Repeater Runat="server" ID="rptrSub">
            <ItemTemplate>
                <asp:Label ID="lblPartName" runat="server" ></asp:Label>
                <asp:Label ID="lblManufacturerName" runat="server" ></asp:Label>
            </ItemTemplate>
        </asp:Repeater>
     </ItemTemplate>
</asp:Repeater>

I bind the data to the repeaters in the code behind as follows:

var q = from inventories in itemContext.Inventory.Include("Parts.Manufacturer")
        select inventories;

List<Inventory> inventoryList = q.ToList();
rptrMain.DataSource = inventoryList ;
rptrMain.ItemDataBound += new RepeaterItemEventHandler(rptrMain_ItemDataBound);
rptrMain.DataBind();

void rptrMain_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        Inventory inventory = e.Item.DataItem as Inventory;
        Label lblName = e.Item.FindControl("lblName") as Label;
        Label lblDescription = e.Item.FindControl("lblDescription") as Label;

        lblName.Text = inventory.Name;
        lblDescription.Text = inventory.Description;

        Repeater rptrSub = e.Item.FindControl("rptrSub") as Repeater;
        rptrSub.DataSource = inventory.Parts;
        rptrSub.ItemDataBound += new RepeaterItemEventHandler(rptrSub_ItemDataBound);
        rptrSub.DataBind();
    }
}

void rptrSub_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        Part part = e.Item.DataItem as Part;
        Label lblPartName = e.Item.FindControl("lblPartName ") as Label;
        Label lblManufacturerName = e.Item.FindControl("lblManufacturerName") as Label;

        lblPartName.Text = part.Name;
        lblManufacturerName.Text = part.Manufacturer.Name
    }
}

Inventory has a 1 to many relation to Part and Part has a many to one relation with Manufacturer.

Now my question is: How do I filter the child entities of Inventory in the LINQ query?
For example I would only like to retrieve all Parts that are of a certain PartType.
Like this:

where parts.Type == Tire

I did find this helpful tip http://blogs.msdn.com/b/alexj/archive/2009/06/02/tip-22-how-to-make-include-really-include.aspx
Although that still does not allow me to filter the child entities?

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:16:37+00:00Added an answer on May 17, 2026 at 12:16 am

    i think the best way is to filter the datasource which is used for rptrMain before calling DataBind().
    for example the code maybe something like this:

    var q = from inventories in itemContext.Inventory.Include("Parts.Manufacturer")
            where inventories.Part.Type == Tire
            select inventories;
    ...
    

    edited after 1st comment:

    i declared two new classes including needed fields for formatting the query:

    class AbstractPartsClass
    {
        public string Name { get; set; }
        public string ManufacturerName { get; set; }
    }
    class AbstractInventoryClass
    {
        public string Name { get; set; }
        public string Description { get; set; }
        public List<AbstractPartsClass> AbstractParts { get; set; }
    }
    

    then i changed the query and some part of your code as below:

    var q = from inventory in itemContext.Inventory.Include("Parts.Manufacturer")
            let filteredParts = from part in inventory.Parts
                                where part.Type == Tire //any filter condition
                                select new AbstractPartsClass()
                                {
                                    Name = part.Name,
                                    ManufacturerName = part.ManufacturerName
                                }
            select new AbstractInventoryClass()
            {
                Name = inventory.Name,
                Description = inventory.Description,
                AbstractParts = filteredParts.ToList(),
            };
    List<AbstractInventoryClass> inventoryList = q.ToList();
    rptrMain.DataSource = inventoryList ;
    rptrMain.ItemDataBound += new RepeaterItemEventHandler(rptrMain_ItemDataBound);
    rptrMain.DataBind();
    
    void rptrMain_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Inventory inventory = e.Item.DataItem as AbstractInventoryClass; //changed line
            Label lblName = e.Item.FindControl("lblName") as Label;
            Label lblDescription = e.Item.FindControl("lblDescription") as Label;
    
            lblName.Text = inventory.Name;
            lblDescription.Text = inventory.Description;
    
            Repeater rptrSub = e.Item.FindControl("rptrSub") as Repeater;
            rptrSub.DataSource = inventory.AbstractParts; //changed line
            rptrSub.ItemDataBound += new RepeaterItemEventHandler(rptrSub_ItemDataBound);
            rptrSub.DataBind();
        }
    }
    void rptrSub_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Part part = e.Item.DataItem as AbstractPartsClass; //changed line
            Label lblPartName = e.Item.FindControl("lblPartName ") as Label;
            Label lblManufacturerName = e.Item.FindControl("lblManufacturerName") as Label;
    
            lblPartName.Text = part.Name;
            lblManufacturerName.Text = part.ManufacturerName
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.