9/26/2008

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
)
RETURNS int
AS
BEGIN

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

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

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

END
GO

3 comments:

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"

http://www.joesak.com/2007/09/13/three-scripts-i-wrote-for-dotnetnuke-skins/

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.
http://webtipstoremember.blogspot.com/2010/03/how-to-get-tabid-of-every-ancestor-of.html

Related Posts with Thumbnails

Recent Comments

Free DotNetNuke Stuff

Free DotNet Videos

  © Blogger template The Professional Template by Ourblogtemplates.com 2008

Back to TOP