[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Simple menu control shows childitems count =0

Posted on 2007-07-26
14
Medium Priority
?
758 Views
Last Modified: 2012-05-05
This cant be that hard. I have an XML with 1 parent node and 3 childnodes. I bind this to a Menu Control. I want to set the URL of the code behind. I do this in *** OnMenuItemDataBound ***

**** THE COUNT Comes as zero*** why??

Protected Sub test(ByVal sender As Object, ByVal e As MenuEventArgs)
        Dim t As Integer = e.Item.ChildItems.Count
         If e.Item.Value = "jobseekers" Then
            Dim test As String = e.Item.ChildItems(0).Text
            e.Item.ChildItems(0).NavigateUrl = Page.ResolveUrl("~/" + ConfigurationManager.AppSettings("jobseekerfolder") + "/" + e.Item.ChildItems(0).NavigateUrl)
        End If
END

**** I see the menu on the screen with the child nodes. The XML is this:

<JobSeekers>
    <PostResume url="postresume.aspx"></PostResume>
    <SearchJobs url="jobsearch.aspx"></SearchJobs>
    <MyFavorites url="MyFavorites.aspx"></MyFavorites>
  </JobSeekers>
0
Comment
Question by:Camillia
  • 7
  • 7
14 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19575373
What is the parent element, and what are the child elements?

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19575379
How are you binding the menu to the XML?

Bob
0
 
LVL 7

Author Comment

by:Camillia
ID: 19575531
That XML is it. Parent node is "jobseekers". Child Nodes is under it: postresume, searchjobs and myfavorites.

*********I have this:
<asp:Menu runat="server" ID="Menu1" OnMenuItemDataBound="test" StaticEnableDefaultPopOutImage="false"   Orientation="Horizontal" DataSourceID="XmlDataSource2">
  <DataBindings>
  <asp:MenuItemBinding DataMember="JobSeekers" Value="jobseekers" Text="Job Seekers" > </asp:MenuItemBinding >
 
  </DataBindings>

</asp:Menu>


********and I bind like this:
<asp:XmlDataSource ID="XmlDataSource2" Runat="server" DataFile="~/UserControls/sitemap.xml">
</asp:XmlDataSource>

******** and the XML is what I posted..

***** Maybe I need to do "<asp:MenuItemBinding> for the rest of the nodes??? *****
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 96

Expert Comment

by:Bob Learned
ID: 19575795
Usually a SiteMap.xml looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="~/Default.aspx" title="Home">
     <siteMapNode url="~/Books/Default.aspx" title="Books">
       <siteMapNode url="~/Books/Novels.aspx" title="Novels" />
       <siteMapNode url="~/Books/History.aspx" title="History" />
       <siteMapNode url="~/Books/Romance.aspx" title="Romance" />
     </siteMapNode>
     <siteMapNode url="~/Electronics/Default.aspx" title="Electronics" />
     <siteMapNode url="~/DVDs/Default.aspx" title="DVDs" />
     <siteMapNode url="~/Computers/Default.aspx" title="Computers" />
  </siteMapNode>
</siteMap>

And, you would bind to a SiteMapDataSource.

Bob
0
 
LVL 7

Author Comment

by:Camillia
ID: 19575843
I didnt use a sitemap. I used an XML and binding to an XMLDatasource....i've seen example of this...

http://www.aspdotnetcodes.com/Asp.Net_Menu_Control_XmlDataSource.aspx

*** but what am I missing that count comes out as zero??

I tried this as well:

<asp:Menu runat="server" ID="Menu1" OnMenuItemDataBound="test" StaticEnableDefaultPopOutImage="false"   Orientation="Horizontal" DataSourceID="XmlDataSource2">
  <DataBindings>
  <asp:MenuItemBinding DataMember="JobSeekers" Value="jobseekers" Text="Job Seekers" > </asp:MenuItemBinding >
  <asp:MenuItemBinding DataMember="PostResume" Value="PostResume"  NavigateUrlField="url" Text="Post Resume123" > </asp:MenuItemBinding >
   <asp:MenuItemBinding DataMember="SearchJobs" Value="SearchJobs"  NavigateUrlField="url" Text="Search Jobs123" > </asp:MenuItemBinding >
   <asp:MenuItemBinding DataMember="MyFavorites" Value="MyFavorites"  NavigateUrlField="url" Text="MyFavorites123" > </asp:MenuItemBinding >
 
  </DataBindings>

</asp:Menu>
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19575978
I don't see TextField and ValueField for the MenuItemBinding entries.  The example shows those:

<asp:MenuItemBinding DataMember="Menu" TextField="text" ValueField="text" NavigateUrlField="url" />

Bob
0
 
LVL 7

Author Comment

by:Camillia
ID: 19576476
Geez, that didnt work either. I did this:
****Changed the XML to this:
  <Menu text="" url="">
    <SubMenu text="PostResume" url="postresume.aspx"></SubMenu>
    <SubMenu text="SearchJobs" url="jobsearch.aspx"></SubMenu>
    <SubMenu text="MyFavorites" url="MyFavorites.aspx"></SubMenu>

  </Menu>

*** Chagned Menu control to this:
<asp:Menu runat="server" ID="Menu1" OnMenuItemDataBound="test" StaticEnableDefaultPopOutImage="false"   Orientation="Horizontal" DataSourceID="XmlDataSource2">
  <DataBindings>
  <asp:MenuItemBinding DataMember="Menu"  />
  <asp:MenuItemBinding DataMember="SubMenu" NavigateUrlField="url" TextField="text"
                    ValueField="text" />
 </DataBindings>

</asp:Menu>

***Same XML datasource. Made sure the path is correct But still the count comes as zero which means...Dim test As String = e.Item.ChildItems(0).Text gives me a null value...

Really dont want to change this to Sitemap...if i dont find other examples , i will try the sitemap solution...

how could this be so hard??
0
 
LVL 7

Author Comment

by:Camillia
ID: 19576559
You know, with this code:
If e.Item.Value = "Menu" Then
 End If

I set a debug and e.item.value comes out as the nodes of that XML.  Wondering if my code of "e.item.childitems(0).text" is incorrect and I should just look at e.item.value??
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1500 total points
ID: 19576570
I ran the example from the link that you posted, and I got a menu with sub-menus.  I modified the XML to get something that seemed like what you were looking for:

       <asp:Menu ID="Menu1" runat="server" DataSourceID="XmlDataSource1" MaximumDynamicDisplayLevels="4"
            StaticDisplayLevels="1" DynamicHorizontalOffset="1" DynamicVerticalOffset="1">
            <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
            <DynamicHoverStyle BackColor="#990000" Font-Bold="False" ForeColor="White" />
            <DynamicMenuStyle BackColor="#FFFBD6" />
            <StaticSelectedStyle BackColor="#FFCC66" />
            <DynamicSelectedStyle BackColor="#FFCC66" />
            <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
            <DataBindings>
                <asp:MenuItemBinding DataMember="SubMenu" NavigateUrlField="url" TextField="text"
                    ValueField="text" />
            </DataBindings>
            <StaticHoverStyle BackColor="#990000" Font-Bold="False" ForeColor="White" />
        </asp:Menu>
        <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/MenuList.xml"></asp:XmlDataSource>
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19576572
<?xml version="1.0" encoding="utf-8" ?>
<Menu>
      <SubMenu text="PostResume" url="postresume.aspx"></SubMenu>
      <SubMenu text="SearchJobs" url="jobsearch.aspx"></SubMenu>
      <SubMenu text="MyFavorites" url="MyFavorites.aspx"></SubMenu>
</Menu>
0
 
LVL 7

Author Comment

by:Camillia
ID: 19576609
Yeah, and then in the code behind i have:
If e.Item.Value = "PostResume" Then
 e.Item.NavigateUrl = Page.ResolveUrl("~/" + ConfigurationManager.AppSettings("jobseekerfolder") + "/" + e.Item.NavigateUrl)
End

and it gets the value correctly. I guess then "childitems(0)" is wrong in this scenario....

*** So, I'll look at EACH NODE like that...i guess no way to look at "<Menu>"s childnodes?
0
 
LVL 7

Author Comment

by:Camillia
ID: 19576656
even tried this:

  Dim childItem As MenuItem
        For Each childItem In e.Item.ChildItems
            Dim test As String = e.Item.Text
        Next

but since childitems come as zero, that doesnt work.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19576687
Actually, what is that code supposed to accomplish?

Bob
0
 
LVL 7

Author Comment

by:Camillia
ID: 19576998
i downloaded a starter-kit from www.asp.net. It has a treeview and I want to change the treeview to menu control because i want to position the control horizontally. Not like a treeview...

 So i removed the treeview and it's XML and added my own XML and menu control...

What I have now works but wondering why that childitems didnt work. Not a big deal ..this gets me going..
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question