I create have a TreeView bound to a SiteMap. It works great.
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1">
</asp:TreeView>
Now I want to change the way the selected node looks.
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1">
<NodeStyle ImageUrl="~/Images/Page.png" />
<SelectedNodeStyle ImageUrl="~/Images/Page_Hot.png" />
</asp:TreeView>
The thing is, the current page is not automatically selected on the tree (why MSFT, why?). This is not the end of the world. So, I created a little code behind like this:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
return;
TreeView1.TreeNodeDataBound += new TreeNodeEventHandler(TreeView1_TreeNodeDataBound);
}
void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
{
var _CurrentUrl = Request.Url.AbsolutePath;
e.Node.Selected = (e.Node.NavigateUrl == _CurrentUrl);
}
But still the node is not selected. My gut tells me it's the wrong event.
Any help?
Thanks // Jerry