Finding a tab's parent by level

This is a simple but useful user defined function I have implemented in order to recursively find a tab's parent on a specific level. Syntax is as follows:

select dbo.udfGetParentByLevel (level, tabid)

where level is the level you need (0,1,2 etc.) and tabid is the id of the tab for which you need to find the parent.

Nothing much, but can save you in certain scenarios.

CREATE FUNCTION udfGetParentTabByLevel
-- Add the parameters for the function here
@parentlevel int, @initialtabid int

declare @level int
declare @tabid int
declare @parentid int

select @level = level, @tabid=tabid, @parentid=parentid from tabs where tabid=@initialtabid

while @level > @parentlevel
select @level = level, @tabid=tabid, @parentid=parentid from tabs where tabid=@parentid
-- Return the result of the function
RETURN @tabid



Joe,  September 27, 2008 at 6:48 PM  

I've written a similar function in VB.NET that does the same thing based on active tab. I use it to display the top ancestor name on all of its' child pages, and to add a class to the navigation menu to keep the top ancestors' button "lit up"


Gyromyristis September 28, 2008 at 12:49 PM  

Thank you for letting us know, these are simple but very useful scripts, I'll be sure to include them in my skins too!

Kurt Meredith March 9, 2010 at 6:56 PM  

Here is another method of finding the TabID of every ancestor of an active Tab. It uses recursion to create an Array of TabIDs and Javascript, JQuery and CSS to style the top-level navigation element.

Related Posts with Thumbnails

Recent Comments

Free DotNetNuke Stuff

Free DotNet Videos

  © Blogger template The Professional Template by Ourblogtemplates.com 2008

Back to TOP