我想在C#中的HTML控件中获取所有html标签。 这是我的HTML代码..
<div id="nav" runat="server" style="position: absolute;">
<ul id="navList">
<li runat="server" id="HOME">
<a id="a1" runat="server" href="#">HOME</a>
<!-- This is the sub nav -->
<ul class="listTab">
<li runat="server" id="HM1"><a id="a2" runat="server" href="#">About This Template</a></li>
<li runat="server" id="HM2"><a id="a3" runat="server" href="#">Flash</a></li>
<li runat="server" id="HM3"><a id="a4" runat="server" href="#">jQuery</a></li>
</ul>
</li>
<li runat="server" id="BLOG">
<a id="a5" runat="server" href="#">BLOG</a>
<!-- This is the sub nav -->
<ul class="listTab">
<li runat="server" id="BM1"><a id="a6" runat="server" href="#">MENU 1</a></li>
<li runat="server" id="BM2"><a id="a7" runat="server" href="#">MENU 2</a></li>
<li runat="server" id="BM3">
<a id="a8" runat="server" href="#">MENU 3</a>
<ul class="listTab">
<li runat="server" id="BM3S1"><a id="a9" runat="server" href="#">MENU 3 SUB 1</a></li>
<li runat="server" id="BM3S2"><a id="a10" runat="server" href="#">MENU 3 SUB 2</a></li>
<li runat="server" id="BM3S3"><a id="a11" runat="server" href="#">MENU 3 SUB 3</a></li>
</ul>
</li>
</ul>
</li>
<li runat="server" id="ABOUT">
<a id="a12" runat="server" href="#">About</a>
<!-- This is the sub nav -->
<ul class="listTab">
<li runat="server" id="AM1"><a id="a13" runat="server" href="#">ABOUT MENU 1</a></li>
<li runat="server" id="AM2"><a id="a14" runat="server" href="#">ABOUT MENU 2</a></li>
<li runat="server" id="AM3"><a id="a15" runat="server" href="#">ABOUT MENU 3</a></li>
</ul>
</li>
<li runat="server" id="PORTFIL"><a id="a16" runat="server" href="#">Porfolio</a></li>
<li runat="server" id="CONTACT"><a id="a17" runat="server" href="#">Contact</a></li>
</ul>
</div>
如何从上面的HTML代码中获取代码。这是我的方法,它只提供&#34; div&#34;标签和&#34; li&#34;代码。我的代码有什么问题。请帮忙..
private void LoadMenues(HtmlGenericControl subMenu)
{
foreach (HtmlGenericControl c in subMenu.Controls.OfType<HtmlGenericControl>())
{
string id = c.ID;
string x = c.TagName; // <----**
MenuModel m = new MenuModel();
m.vcMenuID = id;
MenuModel menu = objCommon.MenuLookup(m).FirstOrDefault();
if (menu == null)
{
menu = new MenuModel();
menu.vcMenuID = id;
menu.intParentMenuID = pid;
menu.bIsActiveMenu = 1;
pid = objCommon.InsertMenu(menu);
}
else
{
pid = menu.intMenuID;
}
LoadMenues(c);
}
if (pid != null)
pid = objCommon.GetMinPID(subMenu.ID);
}
答案 0 :(得分:1)
您的代码似乎没有任何问题,并且您以递归方式调用该函数。
但请注意,您只能获得使用此代码定义runat="server"
属性的控件。
您希望获得并且没有获得的控件是那些没有它的控件吗?