using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
DataTable dt = new DataTable("Menu");
protected void Page_Load(object sender, EventArgs e)
{
dt.Columns.Add("MenuId");
dt.Columns.Add("MenuName");
dt.Columns.Add("ParentMenuId");
dt.Columns.Add("NavigationUrl");
dt.Rows.Add(new string[] { "1","Home","0","http://www.google.com" });
dt.Rows.Add(new string[] { "2", "Sub_Home_1", "1", "http://www.yahoo.com" });
dt.Rows.Add(new string[] { "3", "About Us", "0", "http://www.reliancemoney.com" });
dt.Rows.Add(new string[] { "4", "Sub_AboutUs_1", "3", "http://www.relince.com" });
dt.Rows.Add(new string[] { "5", "Sub_AboutUs_2", "3", "http://www.codeproject.com" });
dt.Rows.Add(new string[] { "6", "Contact Us", "0", "http://www.sqlauthority.com" });
dt.Rows.Add(new string[] { "7", "Sub_Contact Us_1", "6", "http://www.crm.com" });
dt.Rows.Add(new string[] { "8", "Sub_Sub_Contact Us_1", "7", "http://www.firebug.com" });
dt.Rows.Add(new string[] { "9", "Sub_Sub_Home_1", "2", "http://www.dotnet.com" });
ShowMenu(mnuTest.Items,0);
}
private void ShowMenu(MenuItemCollection nodes, int parentMenuId)
{
int MenuID;
string MenuName, Url = string.Empty;
DataRow[] ChildMenu = dt.Select("parentMenuId='" + parentMenuId + "'");
if (ChildMenu.Length == 0) return;
foreach (DataRow child in ChildMenu)
{
MenuID = Convert.ToInt32(child.ItemArray[0]);
MenuName = Convert.ToString(child.ItemArray[1]);
Url = Convert.ToString(child.ItemArray[3]);
MenuItem NewNode = new MenuItem(MenuName, MenuID.ToString(),string.Empty,Url);
nodes.Add(NewNode);
ShowMenu(NewNode.ChildItems, MenuID);
}
}
}
What is there in ones name! Here is a LOT!
12 years ago