Making a dynamic crumbtrail?

Soldato
Joined
18 Oct 2002
Posts
9,044
Location
London
To make things simple, say I have a table with:

PageID
ParentID
Title
Content


I can get the navigation to work, as I only show records based on the ParentID == the querystring. Easy stuff.

But how do you go about making a crumbtrail?

Home > p1 > pg1-sub > pg1-sub-sub > currentpage

There must be something more complex to this. I'm pretty stumped.
I'm using ASP.NET if that makes any difference...
 
You can't do it with a single query, as it's recursive (you want to call the record with the ID the same as the current record's Parent ID until the parent ID is null).

So in pseudo code it'd be:

Select ParentID, Title from table where PageID = Current Page ID

Do

Select ParentID, Title from table where PageID = ParentID
If ParentID isn't Null
Add Title to a breadcrumb output string eg: <a href="bleh.aspx?pageid=ParentID">Title</a>

Loop Until ParentID IsNull

...is that enough detail?
 
Cheers Mr B. I did breifly consider working my way through the parentid's like that. It just doesn't seems very 'efficient'. I guess it'd only ever be a max of 5 queries - hardly the end of the world.. :)

I'll give it a go and see what happens... cheers!
 
KingAdora said:
Cheers Mr B. I did breifly consider working my way through the parentid's like that. It just doesn't seems very 'efficient'. I guess it'd only ever be a max of 5 queries - hardly the end of the world.. :)

I'll give it a go and see what happens... cheers!

That's the trouble with SQL, it's not a recursive language. You can fudge it in T-SQL with cursors, but that's not very efficient.

Of course, the best answer is to use some sort of XML document to contain the sitemap, rather than having it in a traditional database structure.

:)
 
Yeah I guess so. There's even a ready-made crumbtrail in VS which uses a XML sitemap. Could be a solution further down the line - but I'd obviously have to do quite a bit of work at the insert phase.
Especially as I don't have a clue how to make the xml file :D
 
KingAdora said:
Yeah I guess so. There's even a ready-made crumbtrail in VS which uses a XML sitemap. Could be a solution further down the line - but I'd obviously have to do quite a bit of work at the insert phase.
Especially as I don't have a clue how to make the xml file :D

Use web.sitemap and the control, it's very simple and there are loads of tutorials on the internet. You could amend the document using the xmldom again fairly simple.
 
Back
Top Bottom