Reperter多层嵌套

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MenuList.aspx.cs" Inherits="AdminBeat_Menu_MenuList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link type="text/css" rel="Stylesheet" href="../Style/Frame.css" />

    <script type="text/javascript" language="javascript" src="http://www.cnblogs.com/JavaScript/jquery-1.8.3.min.js"></script>

    <script type="text/javascript" language="javascript">
        $(document).ready(function() {

            $(".imgHideShow").bind("click", function() {
                var id = $(this).attr("id");
                if ($(this).attr("src") == "../Images/tree_folder1.gif") {
                    $(this).attr("src", "../Images/tree_folder2.gif");
                    $(".tr_" + id).show();

                    $(".tr_" + id).find(".imgHideShow").each(function() {
                        $(this).attr("src", "../Images/tree_folder2.gif");
                        var id = $(this).attr("id");
                        $(".tr_" + id).show();
                    });
                }
                else {
                    $(this).attr("src", "../Images/tree_folder1.gif");
                    $(".tr_" + id).hide();
                    $(".tr_" + id).find(".imgHideShow").each(function() {
                        $(this).attr("src", "../Images/tree_folder1.gif");
                        var id = $(this).attr("id");
                        $(".tr_" + id).hide();
                    });
                }
            });
        });
    
    </script>

</head>
<body>
    <form runat="server" id="form1">
    <table cellpadding='3' cellspacing='1' border='0' class='tableBorder' align="center">
        <tr>
            <th width="100%" height="25" class="tableHeaderText">
                一级导航
            </th>
        </tr>
        <tr style="background: #F6F7F8;">
            <td height="400" valign="top">
                <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr>
                        <td height="25" class='TipTitle'>
                            &nbsp;√ 操作提示
                        </td>
                    </tr>
                    <tr>
                        <td height="30" valign="top" class="TipWords">
                            <p>
                                1、“一级导航”的意思:导航就是一排链接。不同类型的链接即一级导航。</p>
                        </td>
                    </tr>
                    <tr>
                        <td height="10">
                        </td>
                    </tr>
                </table>
                <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr class='forumRowHighLight'>
                        <td height="25">
                            &nbsp;| <a href="MenuAdd.aspx">添加新的一级导航</a>
                        </td>
                    </tr>
                </table>
                <table width="95%" cellspacing="2" cellpadding="0" border="0" align="center" class="">
                    <tr class="TitleHighlight">
                        <td width="6%">
                        </td>
                        <td width="10%">
                            导航编号
                        </td>
                        <td width="20%">
                            导航名称
                        </td>
                        <td width="7%">
                            导航排序
                        </td>
                        <td width="15%">
                            导航级别
                        </td>
                        <td width="20%">
                            导航链接
                        </td>
                        <td width="22%">
                            导航操作
                        </td>
                    </tr>
                    <asp:Repeater ID="rptMenu" runat="server" OnItemDataBound="rptMenu_ItemDataBound"
                        OnItemCommand="rptMenu_ItemCommand">
                        <ItemTemplate>
                            <tr>
                                <td height="30" class="TitleHighlight2">
                                    <img src="../Images/tree_folder1.gif" alt="" class="imgHideShow" id='<%# Eval("ID")%>'>
                                </td>
                                <td class="TitleHighlight2">
                                    <%# Eval("ID") %>
                                </td>
                                <td class="TitleHighlight2">
                                    <%# Eval("Name") %>
                                </td>
                                <td class="TitleHighlight2">
                                    <%# Eval("Order") %></a>
                                </td>
                                <td class="TitleHighlight2">
                                    一级导航
                                </td>
                                <td class="TitleHighlight2">
                                    <%# Eval("Url") %>
                                </td>
                                <td class="TitleHighlight2">
                                    <a href='MenuAdd.aspx?Parent=<%# Eval("ID") %>'>添加二级导航</a> | <a href='MenuEdit.aspx?Parent=<%# Eval("Parent") %>&ID=<%# Eval("ID") %>'>
                                        修改</a> |
                                    <asp:LinkButton ID="lkBtnDelete" runat="server" OnClientClick="return confirm( '您确认要删除吗? ') ;"
                                        CommandArgument='<%# Eval("ID") %>' CommandName="Delete">删除</asp:LinkButton>
                                </td>
                            </tr>
                            <asp:Repeater ID="rptSonMenu" runat="server" OnItemCommand="rpt_ItemCommand">
                                <ItemTemplate>
                                    <tr class='tr_<%# Eval("Parent") %>' style="display: none;">
                                        <td height="30" class="TitleHighlight3">
                                            <img src="../Images/tree_folder1.gif" alt="" class="imgHideShow" id='<%# Eval("ID")%>'>
                                        </td>
                                        <td class="TitleHighlight3">
                                            <%# Eval("ID") %>
                                        </td>
                                        <td class="TitleHighlight3">
                                            <%# Eval("Name") %>
                                        </td>
                                        <td class="TitleHighlight3">
                                            <%# Eval("Order") %>
                                        </td>
                                        <td class="TitleHighlight3">
                                            二级导航
                                        </td>
                                        <td class="TitleHighlight3">
                                            <%# Eval("Url") %>
                                        </td>
                                        <td class="TitleHighlight3">
                                            <a href='MenuAdd.aspx?Parent=<%# Eval("ID") %>'>添加三级导航</a> | <a href='MenuEdit.aspx?Parent=<%# Eval("Parent") %>&ID=<%# Eval("ID") %>'>
                                                修改</a> |
                                            <asp:LinkButton ID="lkBtnDeleteSonMenu" runat="server" OnClientClick="return confirm( '您确认要删除吗? ') ;"
                                                CommandArgument='<%# Eval("ID") %>' CommandName="Delete">删除</asp:LinkButton>
                                        </td>
                                    </tr>
                                    <asp:Repeater ID="rptSSonMenu" runat="server" OnItemCommand="rptSS_ItemCommand">
                                        <ItemTemplate>
                                            <tr class='tr_<%# Eval("Parent") %>' style="display: none;">
                                                <td height="30" class="TitleHighlight4">
                                                </td>
                                                <td class="TitleHighlight4">
                                                    <%# Eval("ID") %>
                                                </td>
                                                <td class="TitleHighlight4">
                                                    <%# Eval("Name") %>
                                                </td>
                                                <td class="TitleHighlight4">
                                                    <%# Eval("Order") %>
                                                </td>
                                                <td class="TitleHighlight4">
                                                    三级导航
                                                </td>
                                                <td class="TitleHighlight4">
                                                    <%# Eval("Url") %>
                                                </td>
                                                <td class="TitleHighlight4">
                                                    <a href='MenuEdit.aspx?Parent=<%# Eval("Parent") %>&ID=<%# Eval("ID") %>'>修改</a>
                                                    |
                                                    <asp:LinkButton ID="lkBtnDeleteSSonMenu" runat="server" OnClientClick="return confirm( '您确认要删除吗? ') ;"
                                                        CommandArgument='<%# Eval("ID") %>' CommandName="Delete">删除</asp:LinkButton>
                                                </td>
                                            </tr>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                </ItemTemplate>
                            </asp:Repeater>
                        </ItemTemplate>
                    </asp:Repeater>
                </table>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using Model;
using BLL;

public partial class AdminBeat_Menu_MenuList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    BLLMenu meBLL = new BLLMenu();
    private void BindData()
    {
        rptMenu.DataSource = meBLL.SelectSonMenu(0);
        rptMenu.DataBind();
    }

    protected void rptMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater rpt = e.Item.FindControl("rptSonMenu") as Repeater;//找到里层的repeater对象
      
            rpt.ItemDataBound+=new RepeaterItemEventHandler(rpt_ItemDataBound);
            rpt.ItemCommand += new RepeaterCommandEventHandler(rpt_ItemCommand);
            DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 
            int ID = Convert.ToInt32(rowv["ID"]); //获取填充子类的id 
            rpt.DataSource = meBLL.SelectSonMenu(ID);
            rpt.DataBind();
        }
    }

    protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater rptSS = e.Item.FindControl("rptSSonMenu") as Repeater;//找到里层的repeater对象
            rptSS.ItemCommand+=new RepeaterCommandEventHandler(rptSS_ItemCommand);
            DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 
            int ID = Convert.ToInt32(rowv["ID"]); //获取填充子类的id 
            rptSS.DataSource = meBLL.SelectSonMenu(ID);
            rptSS.DataBind();
        }
    }

    protected void rptMenu_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {

            int ID = Convert.ToInt32(e.CommandArgument.ToString());
            DeleteMenu(ID);
        }
    }

    protected void rpt_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
            int ID = Convert.ToInt32(e.CommandArgument.ToString());
            DeleteMenu(ID);
        }
    }

    protected void rptSS_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {

            int ID = Convert.ToInt32(e.CommandArgument.ToString());
            DeleteMenu(ID);
        }
    }

    private void DeleteMenu(int ID)
    {
        if (meBLL.DeleteMenu(ID))
        {
            this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "", "<script language=\"javascript\">alert('信息删除成功!');</script>");
            BindData();
        }
        else
        {
            this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "", "<script language=\"javascript\">alert('存在子导航或者其他原因删除失败!');</script>");
        }
    }
}

转载于:https://www.cnblogs.com/suqifeng/archive/2013/02/05/2892462.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值