ASP. NET 2.0 data Tutorial: add the Default. aspx page to each part

Source: Internet
Author: User

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

 
 
  1. < %@ Control Language="C#" AutoEventWireup="true"   
  2. CodeFile="SectionLevelTutorialListing.ascx.cs"   
  3. Inherits="UserControls_SectionLevelTutorialListing" %>  
  4. < asp:Repeater ID="TutorialList" runat="server" EnableViewState="False">  
  5.     < HeaderTemplate>< ul>< /HeaderTemplate>  
  6.     < ItemTemplate>  
  7.         < li>< asp:HyperLink runat="server" 
  8.          NavigateUrl="< %# Eval("Url") %>" Text="< %# Eval("Title")  
  9.          %>">< /asp:HyperLink>  
  10.                 - < %# Eval("Description") %>< /li>  
  11.     < /ItemTemplate>  
  12.     < FooterTemplate>< /ul>< /FooterTemplate>  
  13. < /asp:Repeater> 

SectionLevelTutorialListing. ascx. cs

 
 
  1. using System;  
  2. using System.Data;  
  3. using System.Configuration;  
  4. using System.Collections;  
  5. using System.Web;  
  6. using System.Web.Security;  
  7. using System.Web.UI;  
  8. using System.Web.UI.WebControls;  
  9. using System.Web.UI.WebControls.WebParts;  
  10. using System.Web.UI.HtmlControls;  
  11.  
  12. public partial class UserControls_SectionLevelTutorialListing : System.Web.UI.UserControl  
  13. {  
  14.     protected void Page_Load(object sender, EventArgs e)  
  15.     {  
  16.         // If SiteMap.CurrentNode is not null,  
  17.         // bind CurrentNode ChildNodes to the GridView  
  18.         if (SiteMap.CurrentNode != null)  
  19.         {  
  20.             TutorialList.DataSource = SiteMap.CurrentNode.ChildNodes;  
  21.             TutorialList.DataBind();  
  22.         }  
  23.     }  

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.

  1. ASP. NET 2.0 data Tutorial: add business rules to the BLL class
  2. ASP. NET 2.0 data Tutorial: access a typed dataset through The BLL class
  3. ASP. NET 2.0 data Tutorial: Create a BLL class
  4. Practical skills in ASP. NET Programming
  5. ASP. NET tips

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.