Adding conditional statement to a DataList

Being brand new to 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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
cgcmqAuthor 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?
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 :)

It's towards the bottom of the page.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cgcmqAuthor 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.

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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.