Well done! You are nearly there!
As it happens, I'm working on this EXACT same problem today and I just solved it. So, I'll be happy to share what I came up with.
Your markup looks fine. That you figured out that you need 2 Menu tags and 2 SiteMapDataSource tags and how to use MaximumDynamicDisplayLevels, ShowStartingNode and StartFromCurrentNode is great. It took me a while to get that sorted out in my head so I'm incredibly grateful I don't have to try to explain it (since you already got it).
You are correct in your assumption that you will need to write some code to accomplish what you want. The problem actually has little or nothing to do with the adapters. It has to do with the fact that you are effectively trying to get a menu item to be considered "selected" when its URL isn't actually the URL of the current page. Remember, you are saying that you want the top menu to show its nodes as being selected when a CHILD page in the hierarchy happens to be selected... that that child isn't really in the menu itself. Clear as mud?
OK, no worries. What you want to do makes total sense in the real world and that's all we care about.
Here is the markup I ended up with:
<asp:SiteMapDataSource ID="PrimaryNavDS" runat="server" ShowStartingNode="false" />
<asp:SiteMapDataSource ID="SecondaryNavDS" runat="server" ShowStartingNode="false" StartFromCurrentNode="true" />
<asp:Menu ID="PrimaryNav" runat="server" DataSourceID="PrimaryNavDS" MaximumDynamicDisplayLevels="0" Orientation="Horizontal" CssSelectorClass="PrimaryNav" OnMenuItemDataBound="PrimaryNavItemDataBound" />
<asp:Menu ID="SecondaryNav" runat="server" DataSourceID="SecondaryNavDS" Orientation="Horizontal" CssSelectorClass="SecondaryNav" OnMenuItemDataBound="SecondaryNavItemDataBound" OnDataBound="SecondaryNavFinishedDataBinding" />
And here is the corresponding code that I stuck in the code-behind file:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 Main : System.Web.UI.MasterPage
{
private MenuItem _secondaryNavMenuItemToSelect = null;
protected void Page_Load(object sender, EventArgs e)
{
SiteMapNode node = SiteMap.CurrentNode;
if ((node != null) && (SiteMap.RootNode != null))
{
int offset = 0;
while ((node.ParentNode != null) && (!node.ParentNode.Equals(SiteMap.RootNode)))
{
offset--;
node = node.ParentNode;
}
if (offset != 0)
{
SecondaryNavDS.StartingNodeOffset = offset;
}
}
}
protected void PrimaryNavItemDataBound(object sender, MenuEventArgs e)
{
SiteMapNode node = SiteMap.CurrentNode;
if (SiteMap.RootNode != null)
{
while ((node != null) && (node.ParentNode != null) && (!node.ParentNode.Equals(SiteMap.RootNode)))
{
node = node.ParentNode;
}
if ((node != null) && (node.ParentNode != null) && node.ParentNode.Equals(SiteMap.RootNode) && node.Url.Equals(e.Item.NavigateUrl))
{
e.Item.Selected = true;
}
}
}
protected void SecondaryNavItemDataBound(object sender, MenuEventArgs e)
{
SiteMapNode node = SiteMap.CurrentNode;
if (SiteMap.RootNode != null)
{
while ((node != null) && (node.ParentNode != null) && (node.ParentNode.ParentNode != null) && (!node.ParentNode.ParentNode.Equals(SiteMap.RootNode)))
{
node = node.ParentNode;
}
if ((node != null) && (node.ParentNode != null) && (node.ParentNode.ParentNode != null) && node.ParentNode.ParentNode.Equals(SiteMap.RootNode) && node.Url.Equals(e.Item.NavigateUrl))
{
_secondaryNavMenuItemToSelect = e.Item;
}
}
}
protected void SecondaryNavFinishedDataBinding(object sender, EventArgs e)
{
if (_secondaryNavMenuItemToSelect != null)
{
_secondaryNavMenuItemToSelect.Selected = true;
}
}
}
You'll notice that your markup and my markup are essentially the same, except for the ID values and the choice of CssSelectorClass. Note that I use two different CssSelectorClass values so I can style my two menus independently. Remember that the whole point of CssSelectorClass is to wrap the control with a <div> with a specified class that you can then use to qualify the CSS selectors that you write. I noticed that your markup used the same CssSelectorClass for both menus. I guess you wanted to style your menus identically.
Anyway, I hope this helps.