populate bootstrap navbar in asp.net website from database

蓝咒 提交于 2021-02-11 17:22:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!