我正在尝试在后面的代码中制作嵌套ul
&li
标签。为此,我在我的.aspx
页面中编写了初步代码
<ul class="dropdown" runat="server" id="tabs"> </ul>
我的 C# 代码
DatTable dtOutput = Generix.getData("Get Some Data");
foreach (DataRow drOutput in dtOutput.Rows)
{
HtmlGenericControl li = new HtmlGenericControl("li");
tabs.Controls.Add(li);
HtmlGenericControl anchor = new HtmlGenericControl("a");
anchor.Attributes.Add("href", "#");
anchor.InnerText = Convert.ToString(drOutput["ModuleGroup"]);
li.Controls.Add(anchor);
HtmlGenericControl ul = new HtmlGenericControl("ul");
DatTable dtOutputList = Generix.getData("Get another set of Data");
foreach (DataRow drOutputList in dtOutputList.Rows)
{
HtmlGenericControl ili = new HtmlGenericControl("li");
ul.Controls.Add(ili);
HtmlGenericControl ianchor = new HtmlGenericControl("a");
foreach (DataColumn dcOutputList in dtOutputList.Columns)
{
ianchor.Attributes.Add("href", Convert.ToString(drOutputList["ModuleFileName"]));
}
ianchor.InnerText = Convert.ToString(drOutputList["ModuleName"]);
ili.Controls.Add(ianchor);
}
//tabs.Controls.Add(li);
}
当我运行我的项目并检查菜单上的元素时,我看到类似
<ul id="ctl00_tabs" class="dropdown">
<li class="">
<a href="#">Master</a>
</li>
<li class="">
<a href="#">Cards Management</a>
</li>
<li class="">
<a href="#">Authorization</a>
</li>
<li class="">
<a href="#">Loyalty</a>
</li>
<li class="">
<a href="#">Reports</a>
</li>
</ul>
内部没有创建嵌套ul
标签li
??为什么 ??
例如 :-
<ul id="ctl00_tabs" class="dropdown">
<li class="">
<a href="#">Master</a>
<ul>
<li><a href="Some.aspx"><span>Some Name</span></a></li>
<li><a href="Some1.aspx"><span>Some Name 1</span></a></li>
</ul>
</li>
</ul>