Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 21st, 2010, 06:56 AM
Authorized User
 
Join Date: Jan 2010
Location: Wales, UK
Posts: 31
Thanks: 5
Thanked 2 Times in 2 Posts
Default Nested data controls using LINQ

I have a products table and a categories table like this (simplified)

tblHireItems: itemid(primary key, identity), itemname, categoryid, ...
categories: categoryid(primary key, identity), parentcategoryid, categoryname

There are two levels of category - top level and sub categories

I need to list top level categories as headers, followed by their contained items, followed by their sub-categories with their contained items.

Say like

(main cat1)ACCESS AND HANDLING

-item 1
-item 2

(subcat) Staging boards 600mm Wide
-item 1
-item 2
(subcat) Staging boards 450mm Wide
-item 1
-item 2

(main cat 2) LADDERS
....



I've got a repeater with a nested listview, and linking them together using LINQ . Im stumped about how to add the third one though.

Here is my front end code

Code:
 <asp:Repeater ID="rptCats" runat="server">
    <ItemTemplate><div class="categoryWrapper">
        <h3 class="categoryTitle">
            <asp:Literal ID="Literal1" runat="server" Text='<%# Eval("CatName") %>'></asp:Literal>
        </h3>
       
        <asp:ListView ID="lvHireItems" runat="server" DataSource='<%# Eval("tblHireItems") %>' ItemPlaceholderID="ph1">
            <LayoutTemplate>
              <p runat="server" id="ph1" ></p>

            </LayoutTemplate>
            <ItemTemplate>
                <p><asp:Literal ID="Literal2" runat="server" text='<%# Eval("ItemName") %>'></asp:Literal></p>
            </ItemTemplate>

        </asp:ListView></div>
    </ItemTemplate>
    </asp:Repeater>
and the code behind
Code:
using (items_catsDataContext myDataContext = new items_catsDataContext())
        {
          
var TopCats = from category in myDataContext.categories where category.categoryid >1        
select new {catName = category.categoryName, category.tblHireItems};
                       
            rptCats.DataSource = TopCats;
            rptCats.DataBind();

   
        }
So I need something like

repeater (top cats)
----->listview of items where parentcategoryid = topcat
----->repeater (sub cats)
------> listview of items where parentcategoryid = subcat

Can anyone help?

Last edited by AdamPembs; October 22nd, 2010 at 04:59 AM. Reason: forgot to add the itemDataBound function
  #2 (permalink)  
Old October 30th, 2010, 02:27 AM
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

I "think" there are ways using one of the control events on a repeater to get to a third level of nesting. It's kinda a pain in the ass though. And from what I was able to find, there's no way to go four levels or deeper using .NET controls. You have to do it manually using nested for(each) loops, stringbuilders, and encapsulation.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
  #3 (permalink)  
Old November 3rd, 2010, 10:09 PM
Authorized User
 
Join Date: Jan 2010
Location: Wales, UK
Posts: 31
Thanks: 5
Thanked 2 Times in 2 Posts
Default

I sometime wish we were still using .asp, more code to build something simple, but easier to nest stuff.
  #4 (permalink)  
Old November 3rd, 2010, 11:17 PM
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Yeah, there are certain situations, ie the scenarios it was primarily designed for, where these items come in really handy. The framework and BCL do a good job of allowing developers who don't know UI development to throw some controls onto the page and frees them to focus on their programming. Of course, this is why .NET sites for a long time have had a reputation for being ugly.

However, there are also times when you have to junk the framework when it's not capable of meeting spec. I do a lot of UX design stuff and the framework was never designed for XHTML prototyping. You simply can't take many reasonably complex web designs and use the framework to create predefined output. For that you have to fall back on custom OOP, something much more common among the Java developers. That's one of the reasons I eventually moved away from VB.NET to C#, because C# and Java are almost interchangeable and most of the good books on OOP and design patterns are Java books.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
  #5 (permalink)  
Old November 3rd, 2010, 11:43 PM
Authorized User
 
Join Date: Jan 2010
Location: Wales, UK
Posts: 31
Thanks: 5
Thanked 2 Times in 2 Posts
Default

I have also started to build sites in C# mainly because it is the de facto .net language and most examples and open source applications use it and all the new mobile stuff is using C# or Java. I'm a little cautious about learning Java as it seems to be getting a bad press at the moment wrt security and support being dropped by Apple but then Android uses it so who knows.
  #6 (permalink)  
Old November 4th, 2010, 03:52 AM
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

I think it's a pretty safe bet that Java isn't going anywhere. There are plenty of people who will burn in hell before they touch MS and Java and C# are the only two major languages that really support that. There's a lot of legacy PHP, and PHP 6.0 is supposed to improve Unicode and OOP, but that only starts to bring it in line and despite the fact that Wrox and other publishing houses have published books on it already... it still isn't ready for stable release yet. Last time I checked they hadn't even finished rebuilding the language to support Unicode which was one of their headline claims. PHP is getting older, so I don't seriously see a Java alternative out there for the open source OOP community.

You bring up a good point though, mobile is going to be really important in the coming years. My friend just got back from Event Apart, and they said that mobile devices outsold desktops 2 - 1 last year. I don't think Apple dropping Java is going to be a big deal. Their products have always been high end luxury models, the vast majority of the market is still open. That's why Apple doesn't have the leverage to push flash out of the market either, no matter how much they hate Adobe.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested controls in UserControl return null (FindControl) Lug Velez Schmitz ASP.NET 3.5 Professionals 2 September 6th, 2010 07:56 AM
Insert data using LINQ SQL - page 471 LoriBarber BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 0 March 1st, 2009 08:12 PM
Pivot data: Linq to Objects jimibt BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 September 22nd, 2008 02:22 PM
Accessing Child Controls of Nested Repeater... Jayahar ASP.NET 2.0 Professional 3 October 11th, 2007 02:24 PM
Nested User Controls Error flyin General .NET 3 June 11th, 2004 01:13 PM



All times are GMT -4. The time now is 09:19 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.