开发者

Displaying the menu name within table through ASP code

I have a problem regarding asp.My problem is;the table structure something like that.And those columns have called MenuID,Alt_MenuID,Menu_Adi. Finally, I want to display those items within menu_adi column from menu table.

For Example;

MenuID   Alt_MenuID   Menu_Adi

1           0         Anasayfa
2           0         Urunler
3           2         Bisiklet (Alt_MenuID=2 is equal to MenuID=2,So the sub menu of urunler is bisiklet) 
4           3         Üç Tekerlekli Bisiklet (Alt_MenuID=3 is equal to MenuID=3.So,the sub menu of bisiklet is Üç Tekerlekli Bisiklet) 
5           0         İletişim
6           5         Harita(sub menu of the iletişim)

I want to display like that.

- Anasayfa
- Ürünler
- - Bisiklet (sub menu)
- - - Üç tekerlekli bisiklet ( sub menu of the bisiklet)
- İletişim
- - Harita ( sub menu)

I'm using the function as below for that.

<%function MenuYazdir(MenuID,say) 

Set Liste = Data.Execute("Select MenuID,Alt_MenuID,MenuAd From Menuler Where   Alt_MenuID="& MenuID)
if Liste.Eof=False Then
 Do Until.Liste.Eof
  Response.write("-"& Liste("MenuAd") &"<br>")
  call MenuYazdir(Liste("MenuID"),0)
Liste.MoveNext
Loop
 End if
Set Liste = Nothing

End function%>

<% cal开发者_JS百科l MenuYazdir(0,0)%> 


You're on the right path with a recursive function and a "parent" field, however you seem to be using a function like a sub, doesn't really matter just not the "conventional" way of doing things.

To get the right number of dashes before the item, pass a level variable and increment it before calling the recurse.

Try something like this:

<%
Function MenuYazdir(MenuID,strOutput, intLevel) 

    Set Liste = Data.Execute("Select MenuID,Alt_MenuID,MenuAd From Menuler Where   Alt_MenuID="& MenuID)
    Do While NOT Liste.Eof
        For i = 1 to intLevel
            strOutput = stroutput & "- "
        Next
        strOutput = strOutput & Liste("MenuAd") &"<br>"
        intLevel = intLevel + 1
        strOutput = MenuYazdir(Liste("MenuID"), strOutput, intLevel)
        intLevel = intLevel -1
        Liste.MoveNext
    Loop
    Set Liste = Nothing

End Function
%>

<%= MenuYazdir(0,0) %>

I've removed the need for the if/end if and turned it to a proper function so you can do more with the output (and so you can pass it back into the recurse).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜