我正在使用来自dynamicdrive的 javascript 菜单
我试图从数据库中获取菜单项。我的 aspx 文件包含菜单,当它是静态菜单时它可以正常工作。我的表或我的查询实际产生:
IdPage int, PageTitle varchar(20), PageFileUrl varchar(30), ParentIdPage int
我获取数据的方法
DataRow[] dataRowParent = _dataTable.Select("[ParentIdPage]=" + 0);
foreach (DataRow dr in dataRowParent)
{
HtmlGenericControl li = new HtmlGenericControl("li");
// add <a>
HtmlGenericControl hlink = new HtmlGenericControl("a");
if (dr["PageFileUrl"].ToString() == "") // this item has a submenu.
{
li.Attributes.Add("rel", "ddsubmenu" + dr["IdPage"].ToString());
hlink.Attributes.Add("href", "#");// link should be # when no direct link
hlink.InnerText = dr["PageTitle"].ToString();
li.Controls.Add(hlink);
ulTopMenu.Controls.Add(li);
AddNewUl((int)dr["IdPage"]);
AddSubmenuItems(_dataTable, (int)dr["IdPage"]);
}
else // Direct link ,no submenu
{
hlink.Attributes.Add("href", dr["PageFileUrl"].ToString());
hlink.InnerText = dr["PageTitle"].ToString();
li.Controls.Add(hlink);
ulTopMenu.Controls.Add(li);
}
}
}
private void AddSubmenuItems(DataTable dataTable, int menuId)
{
// create related sub menu
DataView dataView = new DataView(dataTable);
dataView.RowFilter = "ParentIdPage=" + menuId;
foreach (DataRowView subMenuItem in dataView)
{
// find related <ul>
HtmlControl ulControl = (HtmlControl)FindControl("ddsubmenu" + menuId);
// Add new <li><a href="PageFileUrl.aspx" >page title</a> </li>
HtmlGenericControl li = new HtmlGenericControl("li");
HtmlGenericControl hlink = new HtmlGenericControl("a");
hlink.Attributes.Add("href", subMenuItem["PageFileUrl"].ToString());
hlink.InnerText = subMenuItem["PageTitle"].ToString();
li.Controls.Add(hlink);
li.InnerText = subMenuItem["PageTitle"].ToString();
li.Attributes.Add("href", subMenuItem["PageFileUrl"].ToString());
ulControl.Controls.Add(li);
}
}
private void AddNewUl(int menuId)
{
// Add new <ul id="ddsubmenu00" class= "ddsubmenustyle">
HtmlGenericControl newUl = new HtmlGenericControl("ul");
// Set the attributes of the new ul.
newUl.ID = "ddsubmenu" + menuId;
newUl.Attributes.Add("class", "ddsubmenustyle");
placeHolder1.Controls.Add(newUl);
}
我的问题是子菜单没有出现!,怎么了?任何帮助表示赞赏。