左列動態添加菜單Repeater

前台代碼:

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

<!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>
    <STYLE type="text/css">
                .ttl { CURSOR: hand; COLOR: #ffffff; PADDING-TOP: 4px }
                A:active{COLOR: #000000;TEXT-DECORATION: none}
                A:hover{COLOR: #000000;TEXT-DECORATION: none}
                A:link{COLOR: #000000;TEXT-DECORATION: none}
                A:visited{COLOR: #000000;TEXT-DECORATION: none}
                TD {
             FONT-SIZE: 12px; FONT-FAMILY: "Verdana", "Arial", "细明体", "sans-serif"
                }
   </STYLE>
   <SCRIPT language="javascript">
         function showHide(obj){
          var oStyle = obj.parentElement.parentElement.parentElement.rows[1].style;
          oStyle.display == "none" ? oStyle.display = "block" : oStyle.display = "none";
         }
   </SCRIPT>
</head>
<body style="background-color: #9aadcd; margin-left :0; margin-top :0;">
    <form id="form1" runat="server">
    <div>
    <asp:Repeater ID="LeftMenu" runat="server" OnItemDataBound="LeftMenu_ItemDataBound">
  <ItemTemplate>
        <TABLE cellSpacing="0" cellPadding="0" width="159" align="center" border="0">
          <TR>
           <TD width="23"><IMG height="25" src="image/Menu/box_topleft.gif" width="23"></TD>
           <TD class="ttl" οnclick="JavaScript:showHide(this);" width="129" background="image/Menu/box_topbg.gif"><%# Eval("M_CName")%></TD>
           <TD width="7"><IMG height="25" src="image/Menu/box_topright.gif" width="7"></TD>
          </TR>
          <TR style="DISPLAY: none">
           <TD background='image/Menu/box_bg.gif' colSpan='3'>
            

             <TABLE width='100%'>
                 <TBODY>
                 <asp:Repeater ID="LeftMenu_Sub" Runat="server" >
                 <ItemTemplate>
               <TR>
               <TD><IMG height='7' hspace='5' src='image/Menu/arrow.gif' width='5' align='absMiddle'>
                <asp:HyperLink ID ="Hyperlink1" Runat ="server" Target ="mainFrame" NavigateUrl='<%# Eval("M_Directory")%>'>
                 <%# Eval("M_CName")%>
                </asp:HyperLink>
               </TD>
              </TR>
              </ItemTemplate>
              </asp:Repeater>
                          </TBODY>
                         </TABLE>

                    </TD>
               </TR>
            <TR>
            <TD colSpan="3"><IMG height='10' src='image/Menu/box_bottom.gif' width='159'></TD>
            </TR>
         </TABLE>
        </ItemTemplate>
</asp:Repeater> 
        </div>
    </form>
</body>
</html>
 

後台代碼:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class insider_left : System.Web.UI.Page
{
    publicADO ADO = new publicADO();
    protected void Page_Load(object sender, EventArgs e)
    {
        BindMenu();
    }
    private void BindMenu()
    {
        string vsql = "select * from sys_Module where M_Parent=1 order by [order]";
        DataSet myds = ADO.Cds(vsql);
        LeftMenu.DataSource = myds.Tables[0];
        LeftMenu.DataBind();
       
    }
    protected void LeftMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        DataRowView rows = (DataRowView)e.Item.DataItem;
   //     DataView rows = (DataView)e.Item.DataItem;
        int ModuleID = Convert.ToInt32(rows["ModuleID"]);
        string Vsql = "select * from sys_Module where M_Parent=2 and M_PageCode="+ModuleID+" order by [order]";
        Repeater LeftSub = (Repeater)e.Item.FindControl("LeftMenu_Sub");
        DataTable mytb = ADO.Cds(Vsql).Tables [0];
        if (mytb.Rows.Count != 0)
        {
            LeftSub.DataSource = mytb;
            LeftSub.DataBind();
        }

     /*   sys_ModuleTable s_Mt = (sys_ModuleTable)e.Item.DataItem;

        QueryParam qp = new QueryParam();
        qp.Orderfld = " M_OrderLevel ";
        qp.OrderType = 0;
        qp.Where = string.Format("Where M_Close=0 and M_ParentID ={0}", s_Mt.ModuleID);
        int RecordCount = 0;
        ArrayList lst = BusinessFacade.sys_ModuleList(qp, out RecordCount);
        BusinessFacade.Remove_MenuNoPermission(lst);
        if (lst.Count > 0)
        {
            Repeater LeftSubID = (Repeater)e.Item.FindControl("LeftMenu_Sub");
            LeftSubID.DataSource = lst;
            LeftSubID.DataBind();
        }
        else
        {
            e.Item.Visible = false;
        }
      */

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值