public partial class MasterPage : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { CreateMenuControl(); PopulateMenu(); } private void CreateMenuControl() { Menu1.DataSource = GetSiteMapDataSource(); Menu1.DataBind(); } private SiteMapDataSource GetSiteMapDataSource() { XmlSiteMapProvider xmlSiteMap = new XmlSiteMapProvider(); System.Collections.Specialized.NameValueCollection myCollection = new System.Collections.Specialized.NameValueCollection(1); myCollection.Add("siteMapFile", "Web.sitemap"); xmlSiteMap.Initialize("provider", myCollection); xmlSiteMap.BuildSiteMap(); SiteMapDataSource siteMap = new SiteMapDataSource(); return siteMap; } private void PopulateMenu() { DataSet ds = GetDataSetForMenu(); Menu menu = new Menu(); foreach (DataRow parentItem in ds.Tables["tabs"].Rows) { MenuItem categoryItem = new MenuItem((string)parentItem["tabname"]); menu.Items.Add(categoryItem); foreach (DataRow childItem in parentItem.GetChildRows("tabpages")) { MenuItem childrenItem = new MenuItem((string)childItem["pagename"]); categoryItem.ChildItems.Add(childrenItem); } } Panel1.Controls.Add(menu); Panel1.DataBind(); } private DataSet GetDataSetForMenu() { MySqlConnection myConnection = new MySqlConnection(); string conn = @"Server=127.0.0.1;Database=find;user=root;password=Server123"; myConnection.ConnectionString=conn; myConnection.Open(); MySqlDataAdapter adtap = new MySqlDataAdapter("select * from tabs",myConnection); MySqlDataAdapter adtapage = new MySqlDataAdapter("select * from tabpages", myConnection); DataSet ds = new DataSet(); adtap.Fill(ds,"tabs"); adtapage.Fill(ds,"tabpages"); ds.Relations.Add("tabpages", ds.Tables["tabs"].Columns["tabid"], ds.Tables["tabpages"].Columns["tabno"]); return ds; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)