Maximizing.ASP.dot.NET.Real.World.ObjectOriented.Development [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Maximizing.ASP.dot.NET.Real.World.ObjectOriented.Development [Electronic resources] - نسخه متنی

Jeffrey Putz

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید






Navigation Controls


The treeView and SiteMapPath controls, introduced in ASP.NET v2.0, are fantastic additions to the built-in controls. As with the other controls mentioned in this chapter, they can be programmatically manipulated, but they can also be programmed declaratively.

treeView has been around for a long time; it was originally offered in a somewhat less robust form as part of a control package downloadable from Microsoft. Listing 13.4 demonstrates the simple declaration of a TReeView to create the navigation shown in Figure 13.2.

Listing 13.4. treeView declaration


<asp:TreeView ID="MyTree" Runat="Server" ShowLines="true" Font-Names="Verdana, Arial">
<Nodes>
<asp:TreeNode Text="Home" NavigateUrl="~/Default.aspx" Expanded="true">
<asp:TreeNode Text="Page 1" NavigateUrl="~/Page1.aspx" />
<asp:TreeNode Text="Page 2" NavigateUrl="~/Page2.aspx" />
</asp:TreeNode>
</Nodes>
</asp:TreeView>

Figure 13.2. The treeView rendered in the browser


What's the deal with the tilde (~) in the navigation path? Using the tilde references the root of an application. If you have a subfolder in the site acting as an application, the tilde points to that root, not the site root. In Listing 13.4, an application residing in http://www.mysite.com/myapp would resolve the above path to http://www.mysite.com/myapp/Page1.aspx.

If you prefer to separate the data from the control, you can bind an external XML file to the TReeView and an XmlDataSource control. Just as you used a SqlDataSource control to bind to various data controls, a SiteMapDataSource control can be used to bind hierarchical data to a treeView. Listing 13.5 shows the web.sitemap file, where SiteMapDataSource gets its data. This functionally produces the same output shown in Figure 13.2

Listing 13.5. Using SiteMapDataSource with treeView and web.sitemap

Code from an .aspx page

[View full width]


<asp:TreeView ID="MyTree" Runat="Server" ShowLines="true" Font-Names="Verdana, Arial"
DataSourceID="MapSource" />
<asp:SiteMapDataSource id="MapSource" runat="server" />

web.sitemap


<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
<siteMapNode title="Home" url="~/Default.aspx">
<siteMapNode title="Page 1" url="~/Page1.aspx" />
<siteMapNode title="Page 2" url="~/Page2.aspx" />
</siteMapNode>
</siteMap>

The SiteMapPath control creates a breadcrumb trail of links through the site, based on the web.sitemap file. All it requires is declaration in the page like this: <asp:SiteMapPath ID="SiteMapPath1" Runat="server" />. If you were on Page1.aspx described in the web.sitemap file from Listing 13.5, and it contained this control, you'd get the output shown in Figure 13.3. This is another great example of how little work is required on your part with some declarative controls.

Figure 13.3. The SiteMapPath control rendered in the browser


/ 146