In our site, this course is divided into different categories-Basic Reporting, Filtering, Custom Formatting, and so on-each category has a folder with the aspx page of the corresponding course. In addition, each folder contains a Default. aspx page. All courses in this section are displayed on this default page. For example, you can connect to SimpleDisplay. aspx, DeclarativeParams. aspx, and ProgrammaticParams. aspx through the Default. aspx page in the BasicReporting folder. Here, we can use the SiteMap class and a data display control to display the information of the Site Map defined in the Web. sitemap file.
Let's use Repeater again to display an unordered list, but this time we will display the title and description of the Guide. We need to repeat these tags and Code on each Default. aspx page. We can encapsulate this UI logic into a User Control. Add a folder named UserControls to the site and add a Web user control named SectionLevelTutorialListing. ascx, which contains the following tags:
Default. aspx page: Add a new Web user control to the UserControls folder
SectionLevelTutorialListing. ascx
- < %@ Control Language="C#" AutoEventWireup="true"
- CodeFile="SectionLevelTutorialListing.ascx.cs"
- Inherits="UserControls_SectionLevelTutorialListing" %>
- < asp:Repeater ID="TutorialList" runat="server" EnableViewState="False">
- < HeaderTemplate>< ul>< /HeaderTemplate>
- < ItemTemplate>
- < li>< asp:HyperLink runat="server"
- NavigateUrl="< %# Eval("Url") %>" Text="< %# Eval("Title")
- %>">< /asp:HyperLink>
- - < %# Eval("Description") %>< /li>
- < /ItemTemplate>
- < FooterTemplate>< /ul>< /FooterTemplate>
- < /asp:Repeater>
SectionLevelTutorialListing. ascx. cs
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
-
- public partial class UserControls_SectionLevelTutorialListing : System.Web.UI.UserControl
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- // If SiteMap.CurrentNode is not null,
- // bind CurrentNode ChildNodes to the GridView
- if (SiteMap.CurrentNode != null)
- {
- TutorialList.DataSource = SiteMap.CurrentNode.ChildNodes;
- TutorialList.DataBind();
- }
- }
- }
In the previous Repeater example, I bound the SiteMap data to the Repeater. Of course, this method is also used by the SectionLevelTutorialListing user control. In the Page_Load event, there is a detection program to ensure that this is the first access to the page, not to return) and the URL of this page is mapped to a node in the site map. If this user control is used on the page, no corresponding
<SiteMapNode>, SiteMap. CurrentNode returns null and binds no data to the Repeater control. Suppose we have a CurrentNode. I can bind its ChildNodes set to this Repeater. The Default. aspx page of each part is the parent node of the tutorial in this part. The code shows the connection and description of the tutorial in each part. The following is the screen:
Once this Repeater is created, open the Default. aspx page for each folder in the design view and drag the user control to the desired place.
Figure 14: The user control has been added to the Default. aspx page.
Figure 15: Basic Reporting guide list
Summary
After completing the site map and dashboard page, our tutorial site now has a unified page layout and navigation system. Although our site has many pages, we can update the site page layout and site navigation information in a centralized manner. Specifically, the page layout information is defined in the master page Site. master, and the Site map is defined in Web. sitemap. You do not need to write any code to complete the site page layout and navigation mechanism. Visual Studio provides WYSIWYG design support.
After completing the data access layer and business logic layer and defining a unified page layout and site navigation system, we will explore the common report mode in the next step. In the next three guides, we will see the Basic Report Task-use the GridView, DetailsView, and FormView controls to display the data obtained from the business logic layer.
- ASP. NET 2.0 data Tutorial: add business rules to the BLL class
- ASP. NET 2.0 data Tutorial: access a typed dataset through The BLL class
- ASP. NET 2.0 data Tutorial: Create a BLL class
- Practical skills in ASP. NET Programming
- ASP. NET tips