asp.net+導航+母板+sitemap製作框架!

首先我想告訴大家其實做這個功能也可以用dv畫出來,但我對那不熟練,也沒作過!
所以用2.0做後臺時我還想着在html裏象1.1一樣寫個框架集不久ok了,沒想到2.0已經不支持了!
就納悶。。。然後在baidu,google上搜了一通才明白2.0裏可以用導航+母版+sitemap搞定!
於是我就是試着做了一個,下面就來講一下步驟:
1.首先我覺得這個需要大家把頁面大概都做出來在用框架總合到一起好些!
  新建一個web.sitemap文件
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" enableLocalization="true" >
  <siteMapNode url="" title="CMS" description="">
    <siteMapNode url="" title="種類" description="" resourceKey="Cat">
      <siteMapNode url="Admin/Cat/CatAdd.aspx" title="種類管理" resourceKey="CatManager"></siteMapNode>
    </siteMapNode>
    <siteMapNode url="" title="帳號管理" description="" resourceKey="AccountsManager">
      <siteMapNode url="" title="管理員帳號管理" description="" resourceKey="AdminManager">
        <siteMapNode url="Admin/Admins/AdminAdd.aspx" title="添加管理員" resourceKey="AdminAdd"></siteMapNode>
        <siteMapNode url="Admin/Admins/AdminList.aspx" title="帳號管理" resourceKey="AdminAccountsManager"></siteMapNode>
      </siteMapNode>
      <siteMapNode url="" title="普通帳號管理" description="" resourceKey="CommonAccountsManager">
        <siteMapNode url="Admin/User/UserList.aspx" title="帳號管理" resourceKey="AccountsManagers"></siteMapNode>
      </siteMapNode>
    </siteMapNode>
  </siteMapNode>
</siteMap>
        <siteMapNode url="Admin/User/UserList.aspx" title="帳號管理" resourceKey="AccountsManagers"></siteMapNode>
      </siteMapNode>
    </siteMapNode>
  </siteMapNode>
</siteMap>

因爲需要總和比較多所以我就刪掉了很多,大家也可以看得到他類似xml文件,也是節點之間嵌套
但是能有一對根節點!

2.新建一個PageSum.master文件
然後在裏面拖一個treeview控件和一個contentplaceholder控件
還有一個sitemapdatasource控件,這個控件很奇怪,他不用你去設置數據源,會自己去尋找匹配的web.sitemap文件,而且sitemap文件必須放在項目的根目錄下,否則他無法找到,好象該名字也不行,
大家可以去試試!
這裏我們需要給treeview設置數據源爲sitemapdatasource控件
<body>
    <form id="form1" runat="server">
    <div>
        <table border="0" cellpadding="0" cellspacing="0" style="width: 790px; height: 536px">
            <tr>
                <td rowspan="1" style="width: 94px; height: 19px;">
                </td>
                <td align="center" valign="middle" style="height: 19px">
                   <asp:Localize ID="LocalizeTitle" runat=server Text='<%$ resources:title %>'></asp:Localize>
                </td>
            </tr>
            <tr>
                <td rowspan="1" style="width: 94px">
                    <asp:TreeView ID="treeViewCatList" runat="server" DataSourceID="sitemapDb" Height="502px" NodeIndent="10" meta:resourcekey="treeViewCatListResource1">
                    </asp:TreeView>
                </td>
                <td style="height: 501px; width: 737px;" align="center" valign="middle">
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                    </asp:ContentPlaceHolder>
                </td>
            </tr>
        </table>
    </div>
        <asp:SiteMapDataSource ID="sitemapDb" runat="server" />
    </form>
</body>

3.這樣其實我們已經完成了主要任務了,就剩下將需要總合到框架裏的頁面加進來
首先我們隨便挑一個頁面吧,
.1.在他的page指令加上MasterPageFile="~/Admin/PageSum.master"  等號後面是你的master的路徑
.2.想說下,我在做這步時最鬱悶,我以爲做完上面一步就ok了,結果點擊節點頁面是彈出一個單獨的頁面
   我馬上想也面應該是顯示在contentplaceholder裏
   我就在每個也面里加上這個,就象下面
<asp:Content ContentPlaceHolderID=ContentPlaceHolder1 EnableViewState=true runat=server Visible=true>
    <div>
.......................一大堆東東!
    </div>
</asp:Content>
大家會發現我把表單都刪了,其實我這樣試出來之後自己也嚇了一跳,呵呵!
不過去csdn瞭解原理之後就明白了,大家可以打開母板內容頁的aspx頁面就明白了
所一要加入頁面除了page指令和包括div在內的東西都要喀嚓掉!

....好了,這樣就完成了! 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章