c# - SiteMap.CurrentNode return null when using dynamic sitemap -


i want build dynamic sitemap, highlight parent menu, code behind include 2 methods: page_load , smsource_onmenuitemdatabound that:

 protected void page_load(object sender, eventargs e)     {         if (!ispostback)         {             try             {                 sessions.sitemap = data.getsitemapfile();                 var xmlsmprovider = new xmlsitemapprovider();                 var providerattributes = new namevaluecollection();                 providerattributes.add("sitemapfile", sessions.sitemap);                 xmlsmprovider.initialize("roledemo", providerattributes);                 xmlsmprovider.buildsitemap();                 smsource.provider = xmlsmprovider;                  hormenu.datasource = smsource;                 hormenu.databind();                 }             catch (exception ex)             {                 data.writelog(ex);             }         }     }      protected void smsource_onmenuitemdatabound(object sender, menueventargs e)     {         try         {             if (sitemap.currentnode != null)             {                 if (e.item.text == sitemap.currentnode.title)                 {                     if (e.item.parent != null)                     {                         e.item.parent.selected = true;                     }                     else                     {                         e.item.selected = true;                     }                 }             }         }         catch (exception ex)         {             data.writelog(ex);         }      } 

and aspx code file that:

<asp:sitemapdatasource runat="server" id="smsource" showstartingnode="false"/>      <asp:menu runat="server" id="hormenu" orientation="horizontal" onmenuitemdatabound="smsource_onmenuitemdatabound">          <levelmenuitemstyles>          <asp:menuitemstyle cssclass="main_menu" />          <asp:menuitemstyle cssclass="level_menu" />      </levelmenuitemstyles>      </asp:menu>

the problem sitemap.currentnode return null, highlight menu don't working.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -