IT Community - Software Programming, Web Development and Technical Support

How to Populate menu using sitemap and asp .net menu control and c#:

This is a discussion on How to Populate menu using sitemap and asp .net menu control and c#: within the C# Programming forums, part of the Software Development category; How to Populate menu using sitemap and asp .net menu control and c#:...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 07-23-2007, 11:23 PM
Archer Archer is offline
D-Web Programmer
 
Join Date: Jun 2007
Posts: 52
Archer is on a distinguished road
Question How to Populate menu using sitemap and asp .net menu control and c#:

How to Populate menu using sitemap and asp .net menu control and c#:
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-23-2007, 11:28 PM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: How to Populate menu using sitemap and asp .net menu control and c#:

Depending on your requirements you can populate the tree view control using different sources.

Here I give the example for populating the asp .net menu using sitemap.
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;
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-23-2007, 03:33 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Wink Re: How to Populate menu using sitemap and asp .net menu control and c#:

Copy the following code in to your sitemap,

Code:
<siteMapNode url="Main.aspx" title="Main Page"  description="Main Page">
  <siteMapNode url="Menu1.aspx" title="Menu one"  description="Menu one" />
  <siteMapNode url="Menu2.aspx" title="Menu Two"  description="Menu Two">
  <siteMapNode url="SubMenu1.aspx" title="SubMenu One"  
                                                          description="SubMenu One"/>
  </siteMapNode>
</siteMapNode>
And copy the following code in to your master page,

Code:
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1
                                                                                    "></asp:Menu>

<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />

<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
  </asp:contentplaceholder>
And create the following pages as content pages in your master page.

Main.aspx
Menu1.aspx
Menu2.aspx
SubMenu1.aspx

Then run the project….that’s it…

For more see in my articles,

S.Vinothkumar: ASP.NET Menu using Sitemap

ASP.NET Menu using Sitemap - The Code Project - ASP.NET
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!

Last edited by S.Vinothkumar : 08-23-2007 at 03:35 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-29-2008, 09:23 PM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Smile Re: How to Populate menu using sitemap and asp .net menu control and c#:

<?xml version="1.0" encoding="utf-8" ?>

<siteMap>

<siteMapNode url="Default.aspx" title="Home">

<siteMapNode title="Products" description="Our Products">

<siteMapNode

url="Product1.aspx"

title="My Products"

description="These are my products" />

<siteMapNode

url="Product2.aspx"

title="New Products"

description="Some new products " />

</siteMapNode>

<siteMapNode title="Services" description="Our Services">

<siteMapNode

url="Service1.aspx"

title="ASP.NET Consulting"

description="Best ASP.NET Consulting" />

<siteMapNode

url="Service2.aspx"

title="ASP.NET Training"

description="Best ASP.NET Training" />

</siteMapNode>

</siteMapNode>

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["Categories"].Rows)

{

MenuItem categoryItem = new MenuItem((string)parentItem["CategoryName"]);

menu.Items.Add(categoryItem);

foreach (DataRow childItem in parentItem.GetChildRows("Children"))

{

MenuItem childrenItem = new MenuItem((string)childItem["ProductName"]);

categoryItem.ChildItems.Add(childrenItem);

}

}

Panel1.Controls.Add(menu);

Panel1.DataBind();

}

private DataSet GetDataSetForMenu()

{

SqlConnection myConnection = new SqlConnection(GetConnectionString());

SqlDataAdapter adCat = new SqlDataAdapter("SELECT * FROM Categories", myConnection);

SqlDataAdapter adProd = new SqlDataAdapter("SELECT * FROM Products", myConnection);

DataSet ds = new DataSet();

adCat.Fill(ds, "Categories");

adProd.Fill(ds, "Products");

ds.Relations.Add("Children",ds.Tables["Categories"].Columns["CategoryID"],ds.Tables["Products"].Columns["CategoryID"]);

return ds;

}
private void CreateMenuWithXmlFile()

{

string path = @"C:\MyXmlFile.xml";

DataSet ds = new DataSet();

ds.ReadXml(path);

Menu menu = new Menu();

menu.MenuItemClick += new MenuEventHandler(menu_MenuItemClick);



for (int i = 0; i < ds.Tables.Count; i++)

{

MenuItem parentItem = new MenuItem((string)ds.Tables[i].TableName);

menu.Items.Add(parentItem);



for (int c = 0; c < ds.Tables[i].Columns.Count; c++)

{

MenuItem column = new MenuItem((string)ds.Tables[i].Columns[c].ColumnName);

menu.Items.Add(column);



for (int r = 0; r < ds.Tables[i].Rows.Count; r++)

{

MenuItem row = new MenuItem((string)ds.Tables[i].Rows[r][c].ToString());

parentItem.ChildItems.Add(row);

}

}

}

Panel1.Controls.Add(menu);

Panel1.DataBind();

}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/c-programming/2585-how-populate-menu-using-sitemap-asp-net-menu-control-c.html
Posted By For Type Date
How to Populate menu using sitemap and asp .net menu control and c#: | Web Hosting This thread Refback 12-19-2007 08:41 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
<asp:Menu> Control in Detail? poornima ASP and ASP.NET Programming 4 04-29-2008 09:33 PM
Why do the menu items drop behind some HTML elements.? Pvinothkumar HTML, CSS and Javascript Coding Techniques 1 09-13-2007 05:03 AM
AJAX Menu from XML SaravananJ ASP and ASP.NET Programming 5 09-05-2007 09:50 AM
RightClick option for menu in Flash bluesky Flash Actionscript Programming 2 08-13-2007 11:16 PM
Vertical menu or horizontal menu? capture Web Design Help 1 03-12-2007 06:25 PM


All times are GMT -7. The time now is 10:10 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0