1- Script Title: ddlevelsmenu
2- Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex1/ddlevelsmenu/
3- Describe problem:
Iam using the cool menu ddlevelsmenu (http://www.dynamicdrive.com/dynamici...menu/index.htm
I want to get the menu items from a database..
my aspx file contain the menu and it works fine as static menu (hard coded) :
My table: {}Code:IdPage int, PageTitle varchar(20), PageFileUrl varchar(30), ParentIdPage int
and the code behind:
My Problem is: the submenu does not appear at all.. any help ?Code:private void AddParentMenuItems(int userId) { GetMenuData(userId); 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() == "") // with submenu. { li.Attributes.Add("rel", "ddsubmenu" + dr["IdPage"].ToString()); hlink.Attributes.Add("href", "#"); hlink.InnerText = dr["PageTitle"].ToString(); li.Controls.Add(hlink); ulTopMenu.Controls.Add(li); AddNewUl((int)dr["IdPage"]); AddSubmenuItems(_dataTable, (int)dr["IdPage"]); } else // 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) { HtmlControl ulControl = (HtmlControl)FindControl("ddsubmenu" + menuId); 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) { HtmlGenericControl newUl = new HtmlGenericControl("ul"); newUl.ID = "ddsubmenu" + menuId; newUl.Attributes.Add("class", "ddsubmenustyle"); newUl.Attributes.Add("dir", "rtl"); placeHolder1.Controls.Add(newUl); } protected void Page_Load(object sender, EventArgs e) { AddParentMenuItems(-1); }



Reply With Quote
Bookmarks