xml 与 Repeater层次绑定

<table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td id="Main_tdLeftMenu" width="180" valign="top" style="display: block;">
                <div id="CPHMiddle_body_menu">
                    <div class='tree'>
                        <h1><span>功能菜单</span></h1>
                        <asp:Repeater ID="RptMenu" runat="server" DataSourceID="xmldata">
                            <ItemTemplate>
                                <h2 class='<%#XPath("@Wrap") %>'><a href="#"><%#XPath("@Text")%></a></h2>
                                <ul style='<%#XPath("@Wrap").Equals("on")?"display:block":"" %>'>
                                    <asp:Repeater ID="rptMenuChild" runat="server" DataSource='<%#XPathSelect("itemChild")%>'>
                                        <ItemTemplate>
                                            <li><a><%#XPath("@Text") %></a></li>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                </ul>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                </div>
            </td>
        </tr>
    </table>

<asp:XmlDataSource id='xmldata' runat="server" DataFile="~/NavigateXML/LeftMenu.config" XPath="/items/item"></asp:XmlDataSource>

XML文件:

<?xml version="1.0" encoding="utf-8" ?>
<items>
  <item NavigateUrl="" Text="用户管理" Wrap="on" deny="*">
    <itemChild javascript="" Text="用户管理1" ToolTip="用户管理1" NavigateUrl=""></itemChild>
    <itemChild javascript="" Text="用户管理2" ToolTip="用户管理3" NavigateUrl=""></itemChild>
    <itemChild javascript="" Text="用户管理2" ToolTip="用户管理4" NavigateUrl=""></itemChild>
  </item>
  <item NavigateUrl="" Text="文章管理" Wrap="off" allow="系统管理员">
    <itemChild  Text="文章管理1" ToolTip="文章管理1" NavigateUrl="javascript:alert(1);"></itemChild>
    <itemChild javascript="" Text="文章管理4" ToolTip="文章管理4" NavigateUrl=""></itemChild>
    <itemChild javascript="" Text="文章管理4" ToolTip="文章管理4" NavigateUrl=""></itemChild>
    <itemChild javascript="" Text="文章管理4" ToolTip="文章管理4" NavigateUrl=""></itemChild>
    <itemChild javascript="" Text="文章管理4" ToolTip="文章管理4" NavigateUrl=""></itemChild>
  </item>
</items>

<!--
deny="?"  ?拒绝匿名用户 admin,pub
allow=""  允许权限  admin,pub,*表示全部,auth表示登录用户
deny 与 allow只准出现一个
-->

posted on 2011-03-01 11:13  jianshaohui  阅读(249)  评论(0编辑  收藏  举报

导航