日期:2014-05-18 浏览次数:20500 次
CREATE PROCEDURE GetMenusByUserID @UserID INT --用戶ID AS DECLARE @tmp TABLE (mid INT PRIMARY KEY NOT NULL,pid INT) INSERT INTO @tmp SELECT MenuID,Parentid FROM Nexus WHERE UserID=@UserID DECLARE @OldRecordCnt INT DECLARE @CurRecordCnt INT SELECT @OldRecordCnt=COUNT(*) FROM @tmp WHILE @OldRecordCnt<>0 BEGIN INSERT INTO @tmp SELECT MenuID,Parentid FROM Menu a INNER JOIN @tmp b ON a.MenuID=b.pid WHERE a.MenuID NOT IN(SELECT mid FROM @tmp) SELECT @CurRecordCnt=COUNT(*) FROM @tmp IF @CurRecordCnt=@OldRecordCnt BREAK ELSE SET @OldRecordCnt=@CurRecordCnt END SELECT m.MenuID,m.Name,m.ParentId,m.URL FROM Menu m WHERE m.MenuID IN (SELECT mid FROM @tmp) GO
------解决方案--------------------
你用的是什么控件?可以使用數據綁定啊。
------解决方案--------------------
參考下面這個簡單的示例,我用DataList控件來顯示鏈接,每條記錄使用一個HyperLink,其中NavigateUrl與數據庫中的Link字段(即你說的URL)綁定,而Text(即鏈接的文本)與數據庫中的Name字段綁定。
<asp:DataList ID="DataList2" runat="server" DataKeyField="ID" DataSourceID="SqlDataSource2"> <ItemTemplate> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Link") %>' Text='<%# Eval("Name") %>'></asp:HyperLink><br /> </ItemTemplate> </asp:DataList><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:onlineConnectionString3 %>" SelectCommand="SELECT [ID], [Link], [Name] FROM [MenuClass]"></asp:SqlDataSource>