问题
Can any one give me an example on how to build a bootstrap navbar within an asp.net website dynamically from database according to the role of the logged user (sth like populating asp menu) and keeping the same style of the navbar. any help will be very appreciated as i have searched too much and i can't find a solution.
回答1:
The nav bar in twitter bootstrap is essentially just an unordered list. So make the code as neat or as messy as you prefer, but create a div with an id and a runat="server", and reference that in your code behind. For example, your markup could read:
<div id="myNav" runat="server"/>
In your code behind, read your data items from the database, generate the appropriate HTML, and write it to the DIV. One such example:
Dim sb as New Stringbuilder()
sb.append("<ul>")
sb.append("<li>Item 1</li>")
sb.append("<li>Item 2</li>")
sb.append("</ul>")
myNav.InnerHTML = sb.ToString()
来源:https://stackoverflow.com/questions/24014819/populate-bootstrap-navbar-in-asp-net-website-from-database