Adding conditional statement to a DataList

cgcmq
cgcmq used Ask the Experts™
on
Being brand new to ASP.net I am struggling with the transition from classic ASP so please bear with me.

I have a DataList that returns the following:

ID      ProductName      SubID      SubName
1      Test product A      NULL      NULL
2      Test product B      1      Sub Product i
2      Test product B      2      Sub Product ii
3      Test product C      NULL      NULL


As you can see, some products have sub products while others do not.  I would like to display these records like this:

Test product A
Test product B
     Sub Product i
     Sub Product ii
Test product C

In ASP I would have used a conditional statement to loop through the recordset determining whether or not to write the Product Name or the Sub Name

How would I accomplish this in .Net 2.0?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
You'll want to look into nested DataLists, which are a pain in my opinion.  You'll basically put a 2nd datalist in your 1st datalist's itemtemplate.

Here's an MSDN article I use for reference.  It's about repeater controls but it would take minor changes to work with a DataList.

http://support.microsoft.com/kb/306154

Author

Commented:
You're right, that does look awkward.  Would it be possible to write a stored procedure to output in XML and then using the XmlDataSource &  TreeView? Can the XmlDataSource retrieve a stored procedure?
Commented:
No, but you could write the stored procedure to an in-memory XML file.  I've done this with a treeview before and it worked very well.

And as a matter of fact, I bookmarked the page that showed me how :)

http://www.15seconds.com/issue/041117.htm

It's towards the bottom of the page.

Author

Commented:
I think that should do it.  It is a lot of code for a newbie but I have the Northwind database so, with luck, I can cut & paste the sample and get it working.  Then I can attempt to rewrite it for my database.

Cheers!

Author

Commented:
You may be seeing more of me as I make this transition from ASP.  No, make that 'will be'.

Fred

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial