Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 20th, 2013, 02:17 PM
Registered User
 
Join Date: Aug 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Post ch7 treeview switch statement

Imar,

This is a great resource! Thanks for writing it. I'm having trouble with the switch statement that hides the Menu1 control and shows TreeView1. I coded it exactly as shown on pg. 259, but the DarkGrey theme still shows a menu control in FireFox. I also tried switching the "default" to
Code:
 Menu1.Visible= false; TreeView1.Visible = true;
but the browser still showed the menu. Monochrome has the menu as expected. I've included my source code below:

Code:
         <div id="MenuWrapper">
            <asp:Menu ID="Menu1" runat="server" CssClass="MainMenu" 
                DataSourceID="SiteMapDataSource1" Orientation="Horizontal" 
                StaticEnableDefaultPopOutImage="False">
            </asp:Menu>
            <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" >
                    <LevelStyles>
                        <asp:TreeNodeStyle CssClass="FirstLevelMenuItems" />
                    </LevelStyles>
            </asp:TreeView>
            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" 
                ShowStartingNode="False" />
        </div>
Thank you!
 
Old August 20th, 2013, 02:24 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Good to hear you like the book.

Can you also post the code for the switch statement? And can you post the exact names of the Themes folders under App_Themes?

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 20th, 2013, 02:28 PM
Registered User
 
Join Date: Aug 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Switch statement:
Code:
             switch (Page.Theme.ToLower())
            {
                case "DarkGrey":
                    Menu1.Visible = false;
                    TreeView1.Visible = true;
                    break;
                default:
                    Menu1.Visible = true;
                    TreeView1.Visible = false;
                    break;
            }
My App_Themes folders are "DarkGrey" and "Monochrome".

I also forgot to add I'm using a web application, not a web site project. I commented out the parts of my Web.config file that I'm not using.
 
Old August 20th, 2013, 02:34 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Take a look at this:

Code:
switch (Page.Theme.ToLower())
{
    case "DarkGrey":
        Menu1.Visible = false;
        TreeView1.Visible = true;
        break;
    default:
        Menu1.Visible = true;
        TreeView1.Visible = false;
        break;
}
You're calling ToLower on the theme name, but then compare against a value that is not all lower case (DarkGrey). As such, that branch of the switch is never hit, and you always end up with a Menu and no TreeView.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 20th, 2013, 02:44 PM
Registered User
 
Join Date: Aug 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It works now! Thank you.





Similar Threads
Thread Thread Starter Forum Replies Last Post
switch statement crmpicco Javascript How-To 3 March 9th, 2015 10:37 PM
The switch statement lina C++ Programming 1 September 19th, 2011 03:31 PM
Switch-statement grstad C# 3 June 11th, 2008 06:53 AM
switch statement seymour_glass C# 5 January 24th, 2007 12:08 AM
C# switch statement nalla General .NET 4 December 14th, 2005 05:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.