Camillia
asked on
Simple menu control shows childitems count =0
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).Navig ateUrl = Page.ResolveUrl("~/" + ConfigurationManager.AppSe ttings("jo bseekerfol der") + "/" + e.Item.ChildItems(0).Navig ateUrl)
End If
END
**** I see the menu on the screen with the child nodes. The XML is this:
<JobSeekers>
<PostResume url="postresume.aspx"></Po stResume>
<SearchJobs url="jobsearch.aspx"></Sea rchJobs>
<MyFavorites url="MyFavorites.aspx"></M yFavorites >
</JobSeekers>
**** 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).Navig
End If
END
**** I see the menu on the screen with the child nodes. The XML is this:
<JobSeekers>
<PostResume url="postresume.aspx"></Po
<SearchJobs url="jobsearch.aspx"></Sea
<MyFavorites url="MyFavorites.aspx"></M
</JobSeekers>
How are you binding the menu to the XML?
Bob
Bob
ASKER
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" StaticEnableDefaultPopOutI mage="fals e" Orientation="Horizontal" DataSourceID="XmlDataSourc e2">
<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/s itemap.xml ">
</asp:XmlDataSource>
******** and the XML is what I posted..
***** Maybe I need to do "<asp:MenuItemBinding> for the rest of the nodes??? *****
*********I have this:
<asp:Menu runat="server" ID="Menu1" OnMenuItemDataBound="test"
<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/s
</asp:XmlDataSource>
******** and the XML is what I posted..
***** Maybe I need to do "<asp:MenuItemBinding> for the rest of the nodes??? *****
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.a spx" title="Computers" />
</siteMapNode>
</siteMap>
And, you would bind to a SiteMapDataSource.
Bob
<?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"
<siteMapNode url="~/Books/Novels.aspx" title="Novels" />
<siteMapNode url="~/Books/History.aspx"
<siteMapNode url="~/Books/Romance.aspx"
</siteMapNode>
<siteMapNode url="~/Electronics/Default
<siteMapNode url="~/DVDs/Default.aspx" title="DVDs" />
<siteMapNode url="~/Computers/Default.a
</siteMapNode>
</siteMap>
And, you would bind to a SiteMapDataSource.
Bob
ASKER
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" StaticEnableDefaultPopOutI mage="fals e" Orientation="Horizontal" DataSourceID="XmlDataSourc e2">
<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>
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"
<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>
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
<asp:MenuItemBinding DataMember="Menu" TextField="text" ValueField="text" NavigateUrlField="url" />
Bob
ASKER
Geez, that didnt work either. I did this:
****Changed the XML to this:
<Menu text="" url="">
<SubMenu text="PostResume" url="postresume.aspx"></Su bMenu>
<SubMenu text="SearchJobs" url="jobsearch.aspx"></Sub Menu>
<SubMenu text="MyFavorites" url="MyFavorites.aspx"></S ubMenu>
</Menu>
*** Chagned Menu control to this:
<asp:Menu runat="server" ID="Menu1" OnMenuItemDataBound="test" StaticEnableDefaultPopOutI mage="fals e" Orientation="Horizontal" DataSourceID="XmlDataSourc e2">
<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??
****Changed the XML to this:
<Menu text="" url="">
<SubMenu text="PostResume" url="postresume.aspx"></Su
<SubMenu text="SearchJobs" url="jobsearch.aspx"></Sub
<SubMenu text="MyFavorites" url="MyFavorites.aspx"></S
</Menu>
*** Chagned Menu control to this:
<asp:Menu runat="server" ID="Menu1" OnMenuItemDataBound="test"
<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??
ASKER
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??
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<?xml version="1.0" encoding="utf-8" ?>
<Menu>
<SubMenu text="PostResume" url="postresume.aspx"></Su bMenu>
<SubMenu text="SearchJobs" url="jobsearch.aspx"></Sub Menu>
<SubMenu text="MyFavorites" url="MyFavorites.aspx"></S ubMenu>
</Menu>
<Menu>
<SubMenu text="PostResume" url="postresume.aspx"></Su
<SubMenu text="SearchJobs" url="jobsearch.aspx"></Sub
<SubMenu text="MyFavorites" url="MyFavorites.aspx"></S
</Menu>
ASKER
Yeah, and then in the code behind i have:
If e.Item.Value = "PostResume" Then
e.Item.NavigateUrl = Page.ResolveUrl("~/" + ConfigurationManager.AppSe ttings("jo bseekerfol der") + "/" + 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?
If e.Item.Value = "PostResume" Then
e.Item.NavigateUrl = Page.ResolveUrl("~/" + ConfigurationManager.AppSe
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?
ASKER
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.
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.
Actually, what is that code supposed to accomplish?
Bob
Bob
ASKER
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..
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..
Bob