HTML Navbar items from Database in Asp.net - html

i am Editing an HTML template that has Navbar at top. i am able to edit the navbar items to the items in database but i am unable to change the Number of Items in Navbar menu because that coding is hardcoded in HTML. i want to create Categories in Database and show these in Navbar. these categories are not specific.
coding for Navbar item in HTML is
<li class="active">Home</li>
<li>
Sliders
<ul>
<li>Basic Slider</li>
<li>Right Info Slider</li>
<li>Nivo Slider</li>
<li>Accordion Slider</li>
<li>Thumbnail Slider</li>
</ul>
</li>
these are 5 items in list and these are hardcoded in HTML. when i use database for this purpose my need is that i want all the database items in this Navbar no matter 5,6 or else.
please suggest me what to do

I assume you get data from database in a datatable. Loop through table and create sublist and append in the item you want.
You will need to set id of the li in which a sublist will appear
<li id="liDynamic" runat="server">
And Code to add a sublist in this li
HtmlGenericControl ul = new HtmlGenericControl("ul");
liDynamic.Controls.Add(ul);
foreach (DataRow dr in dt.Rows)
{
HtmlGenericControl li = new HtmlGenericControl("li");
HtmlGenericControl anchor = new HtmlGenericControl("a");
anchor.Attributes.Add("href", "page.htm");
anchor.InnerText = dr["id"].ToString();
li.Controls.Add(anchor);
ul.Controls.Add(li);
}

Related

Page that displays topology of the directory

Is there any way to do this:
<h1>Topology</h1>
<ul><li> Parent Directory</li>
<li> File1.mp4</li>
<li> File2.mp4</li>
<li> File3.mp4</li>
<li> File4.mp4</li>
<li> File5.mp4</li>
<li> File6.mp4</li>
<li> File7.mp4</li>
<li> File8.mp4</li>
<li> File9.mp4</li>
<li> File10.mp4</li>
</ul>
JSFiddle: https://jsfiddle.net/wagyox71/
Is there any way to do this without listing every single file separately?
You can do this with JavaScript.
Create a div for the list, then use a script and an array to populate the div.
The div: <div id="myLinks"></div>
var links = [' Parent Directory', ' File1.mp4', 'File2.mp4', 'etc'];
var ul = document.createElement('ul');
document.getElementById('myLinks').appendChild(ul);
links.forEach(function(name){
var li = document.createElement('li');
ul.appendChild(li);
li.innerHTML += name;
});
You can manually populate the links array, or do it dynamically from a directory on the site via some other call.

Bootstrap menu dropdown level in pug

I am trying to pass to bootstrap navbar an array in jade.
I already did this achievement:
block linkSelected
-var selected = 'index';
-var menu = { 'Sobre': '/sobre', 'blog': '/blog', 'Contato': '/contato' };
and in header:
#navbarCollapse.collapse.navbar-collapse
ul.nav.navbar-nav.navbar-right
each val, key in menu
if selected === key
li.nav-item.active
a.nav-link(href=val, title=key)= key
else
li.nav-item
a.nav-link(href=val+'.html', title=key)= key
So i ended up to this in menu:
<ul class="nav navbar-nav navbar-right">
<li class="nav-item">Sobre</li>
<li class="nav-item">blog</li>
<li class="nav-item">Contato</li>
</ul>
Does anyone know in pug/jade how to achieve the dropdown menu? I only achieved the first level menu... :/
Thank you so much and Happy New Year!

How to use DisplayFor to display a list of hrefs

I have an MVC project that has a list of items. I use
#Html.DisplayFor(m => m.ListOfItems)
when running, this shows the list of items. In the markup, it is displayed like this:
item1item2item3item4
But I want them in an ul so that I can make them hrefs. How do I do this?
simple, use a foreach loop:
<ul>
#foreach(var item in Model.ListOfItems)
{
<li>Some text</li>
}
</ul>

Tabs open according to links on sub menu

In my main navigation bar there is a menu named category & item and it has two submenus which names are category and item respectively. I have only one page to display these two section.
My page is category_item.php and it has two different tabs to display each sections. In this case it is category and item.
So my problem is I need to open category and item tab when clicking on category and item links on the submenu.
UPDATE -
This is code from main navigation bar
<li class="current">
<a>Category & Item</a>
<div class="menu-container">
<div class="menu-link">
Category
</div>
<div class="menu-link current">
Item
</div>
</div>
</li>
This is from category_item.php page
<div class="ui-widget-header ui-corner-top">
<ul>
<li>My Category</li>
<li>My Items</li>
</ul>
</div>
<div id="tabs-1" class="tabs3">
my stuff...
</div>
<div id="tabs-21" class="tabs3">
my stuff...
</div>
Can I know is it possible to do?
Thank you.
You can do this using Javascript. Just toggle property display of that class from none to block and vice versa.
If you are using jQuery, you can do this:
$(document).ready(function() {
$('#cat_link').click(function() {
$('#tabs-1').hide();
$('#tabs-2').show();
return false;
});
$('#item_link').click(function() {
$('#tabs-2').hide();
$('#tabs-1').show();
return false;
});
});
You also have jQuery-UI widget tabs.
If you are using pure javascript, you can do it like this (reference):
function hideshow(which){
if (!document.getElementById)
return
if (which.style.visibility=="visible")
which.style.display="hidden"
else
which.style.display="visible"
}

Multi Level Drop down Menu using Razor in Umbraco

I am trying to build a multi-level dropdrown menu, I'm using umbraco cms.
What I am looking for is something like :
<div id="TopMenu">
<ul class="myMenu">
<li>Home</li>
<li>About Us</li>
<li>Products
<ul>
<li>Products1</li>
<li>Products2</li>
<li>Products3</li>
</ul>
</li>
<li>ContactUs</li>
</ul>
</div><!--TopMenu-->
And in Umbraco I have created cshtml for it to work :
<ul class="myMenu">
<li>Home </li>
#foreach (var page in #Model.AncestorOrSelf(1).Children)
{
string style = "";
if (1 == 1) { style = "class=\"current\""; }
<li><a href="#page.Url" #style>#page.Name</a></li>
}
The Above razor syntax works fine for AncestorOrSelf(1) which is Top level , but i need sub nodes for products which is AncestorOrSelf(2), Does any one knows how to acheive this
Thanx
This is the razor code I'm currently using in my project:
#foreach (var page in Model.AncestorOrSelf(1).Children.Where("Visible"))
{
<li>#page.Name
if (page.Children.Where("Visible").Count() > 0)
{
<ul>
#foreach (var subpage in page.Children.Where("Visible"))
{
<li>#subpage.Name</li>
}
</ul>
}
</li>
}
The inner loop cycles through all the children of the outer loop's node.