本文介绍了从xml读取asp.net中的菜单控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi Guys.
I am trying to create a menu list with the sub items by reading a xml file. I can create ul and li tag in code behind by reading the xml file elements and loop through it and create a html string but, I want to is there any other best way to do this?
My XML file look like below:
<MenuControl>
<Parent href="#" text="Parent1">
</Parent>
<Parent href="#" text="Parent2">
<subMenu href="#" text="Sub Menu 1">
</subMenu>
<subMenu href="#" text="Sub Menu 2">
</subMenu>
</Parent>
<Parent href="#" text="Parent3">
<subMenu href="#" text="Sub Menu 1">
</subMenu>
<subMenu href="#" text="Sub Menu 2">
</subMenu>
</Parent>
<Parent href="#" text="Parent4">
<subMenu href="#" text="Sub Menu 1">
</subMenu>
<subMenu href="#" text="Sub Menu 2">
</subMenu>
</Parent>
<Parent href="#" text="Parent5">
<subMenu href="#" text="Sub Menu 1">
</subMenu>
<subMenu href="#" text="Sub Menu 2">
</subMenu>
</Parent>
<Parent href="#" text="Parent6">
<subMenu href="#" text="Sub Menu 1">
</subMenu>
<subMenu href="#" text="Sub Menu 2">
</subMenu>
</Parent>
<Parent href="#" text="Parent7">
<subMenu href="#" text="Sub Menu 1">
</subMenu>
<subMenu href="#" text="Sub Menu 2">
</subMenu>
</Parent>
</MenuControl>
My file HTML tag should be like the following:
<ul class="topMenu">
<li><a href="#">Parent1</a></li>
<li><a href="#">Parent2</a>
<ul class="subMenu">
<li><a href="#">Sub Menu 1</a></li>
<li><a href="#">Sub Menu 2</a></li>
</ul>
</li>
<li><a href="#">Parent3</a>
<ul class="subMenu">
<li><a href="#">Sub Menu 1</a></li>
<li><a href="#">Sub Menu 2</a></li>
</ul>
</li>
<li><a href="#">Parent4</a>
<ul class="subMenu">
<li><a href="#">Sub Menu 1</a></li>
<li><a href="#">Sub Menu 2</a></li>
</ul>
</li>
<li><a href="#">Parent5</a>
<ul class="subMenu">
<li><a href="#">Sub Menu 1</a></li>
<li><a href="#">Sub Menu 2</a></li>
</ul>
</li>
<li><a href="#">Parent6</a>
<ul class="subMenu">
<li><a href="#">Sub Menu 1</a></li>
<li><a href="#">Sub Menu 2</a></li>
</ul>
</li>
<li><a href="#">Parent7</a>
<ul class="subMenu">
<li><a href="#">Sub Menu 1</a></li>
<li><a href="#">Sub Menu 2</a></li>
</ul>
</li>
</ul>
Please provide me some suggestions to create these HTML tag in code behind.
Thanks in advance.
-Jaffer
推荐答案
这篇关于从xml读取asp.net中的菜单控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!