background preloader

Visual Studio menus

Facebook Twitter

Practical ASP.NET: Database-Driven Menuing System. Practical ASP.NET Drive Your Menus from a Database Table If you'd rather keep your menu structure in a table in your database instead of a file in your Web site, here's all the code you need to implement a database-driven menuing system. One of the questions that I frequently get from people attending my ASP.NET course is "How can I drive my menus from a table in the database instead of from a file in my Website? " (Gratuitous plug: that's course 512 from Learning Tree International). This column provides a problem to that question. In my last column (Managing Menus with a Custom Menu Provider), I briefly described the ASP.NET provider architecture and how to create your own class to manage the connection between the Web.sitemap and your site's menus.

As I also said in that column, creating a provider is easy to do. Public Class PHVDBSiteMap Inherits StaticSiteMapProvider End Class smnMenuHeader = New SiteMapNode(Me, "Customers", Nothing, "Customers") AddNode(smnMenuHeader, smnRoot) Walkthrough: Reading XML Data into a Dataset. ADO.NET provides simple methods for working with XML data. In this walkthrough you will create a Windows application that will load XML data into a dataset.

The dataset will then be displayed in a DataGridView. Finally, an XML Schema based on the contents of the XML file will be displayed in a text box. This walkthrough consists of five main steps: Creating a new project. In this step, you will create a Visual Basic or Visual C# project that will contain this walkthrough. To create the new Windows project From the File menu, create a new project. Because this walkthrough focuses on reading XML data into a dataset, the contents of an XML file is provided. To create the XML file that will be read into the dataset From the Project menu, choose Add New Item. The user interface for this application will consist of the following: A DataGridView control that will display the contents of the XML file as data. To add controls to the form Open Form1 in design view. To test the form. How to use an XML data source in ASP.NET 2.0. Building a Database Driven Hierarchical Menu using ASP.NET 2.0.

Step 1 - Create and Fill a Database Self Join Table Our menu's table will use a self-join relationship which is the simplest method of storing hierarchical data. Child rows will use ParentID to establish a relationship with the MenuID of a parent row as shown below. Figure 1 - Table Overview Let us start by creating a database called MenuDb and a Table called Menu. This can be done by running the following script from Microsoft's Query Analyzer. Listing 1 - Database Script The table you created, displayed below, uses self-join relationships. Figure 2- Parent, Child Relationships Step 2 - Add a Web Page That Implements a Menu and an XmlDataSource Add a new WebForm to your web application.

Listing 2 - Menu and XmlDataSource Web Controls At runtime, the XmlDataSource object is assigned an XML string (shown in step 3) which is then transformed by the XSLT file, TransformXSLT.xsl to another XML format (XSLT is covered in step 4). Step 3 - Retrieve Data and Create Nested Relationships <? Figure 4. VISUAL STUDIO 2010 Using the data binding tools. Walkthrough: Controlling ASP.NET Menus Programmatically. The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location. To complete this walkthrough, you will need: Microsoft Visual Web Developer (Visual Studio).The .NET Framework. To create a file system Web site Open Visual Web Developer.On the File menu, click New Web Site.The New Web Site dialog box appears.

To create the Web.sitemap file In Solution Explorer, right-click the name of your Web site, and then click Add New Item.In the Add New Item dialog box, choose Site Map and then click Add.Add the following XML code to the new file. The first menu displays a single level of static menu items. To create the first menu Because the first menu displays only a single level of static menu items, you need to configure its data source to display the appropriate portion of the Web.sitemap file.

To configure the first data source To create the second menu To coordinate the menus in code To test the menu.