Integrating Dynamic Data with Menu using a SiteMap-File as the source RRS feed

  • Question

  • User1030110584 posted

    I am developing an application that has an asp:Menu control that is populated from an asp:SiteMapDataSource control. I am using Dynamic Data for the CRUD screens for the lookup/code tables.  I'd like to be able to have the Dynamic Data list pages integrated into the menu.  I could manually add them to my Web.sitemap file, but it would be even better if I could have Dynamic Data maintain those entries.  Currently, I have Maintenance.aspx in the sitemap, and it is what a Dynamic Data project usually has as its Default.aspx.  I'd like to have the tables listed on that page integrated with my main menu control so that they appear in a submenu (DynamicMenu) under Maintenance. Is there a way to do this?

     - Mark

    Friday, November 14, 2008 4:15 PM

All replies

  • User-330204900 posted

    Yes there is a way, what you will have to do is load your SiteMapDataSource with the site.map file is you are using a file and then add the nodes to the submenu programatically.

    Or you could generate the site map data programatically as below: 

    protected void Page_Load(object sender, EventArgs e)
    	//System.Collections.IList visibleTables = MetaModel.Default.VisibleTables;
    	System.Collections.IList visibleTables = MetaModel.Default.VisibleTables;
    	if (visibleTables.Count == 0)
    		throw new InvalidOperationException("There are no accessible tables...");
    	var root = new XElement("home");
    	foreach (var table in MetaModel.Default.VisibleTables)
    	XmlDataSource1.Data = root.ToString();
    	Menu1.DataSource = XmlDataSource1;
    	Menu1.Orientation = Orientation.Horizontal;
    private XElement GetChildren(MetaTable parent)
    	XElement children =
    		new XElement("Menu",
    			new XAttribute("title", parent.DisplayName),
    			new XAttribute("url", parent.ListActionPath),
    					from c in parent.Columns
    					where c.GetType() == typeof(MetaChildrenColumn) &&
    						((MetaChildrenColumn)c).ChildTable.Name != parent.Name 
    					orderby c.DisplayName
    					select GetChildren(((MetaChildrenColumn)c).ChildTable));
    	return children;

    This just creats a menu with each menu with each table as an entry in it and submenus are the children tables, but it should give you the idea of where to go from here.

    Hope this helps [:D]

    P.S. here'e the Menu and DataSource: 

    	StaticEnableDefaultPopOutImage="False" MaximumDynamicDisplayLevels="5">
    			NavigateUrlField="url" />
    	<StaticHoverStyle BackColor="#666666" ForeColor="White" />
    <asp:XmlDataSource ID="XmlDataSource1" runat="server" XPath="home/*"></asp:XmlDataSource>
    Friday, November 14, 2008 6:20 PM
  • User1030110584 posted

    Sounds like a workable approach.  I'll give it a try next week and let you know how it turns out.


    - Mark

    Friday, November 21, 2008 12:32 PM