使用Jquery+repeater生成可以收缩的目录

前台的repeater的使用

 <asp:Repeater id="rptCategories" runat="server">
  <HeaderTemplate>
    <table id="table01" width="100%" border="0" cellspacing="0" cellpadding="0">
  </HeaderTemplate>
  <ItemTemplate>
    <tr class ="tr" >
      <td id="tdManiMenu"  >
        <div class ="MainMenu" >
         <asp:Label ID ="lblMenu"  runat ="server" Text ='<%# DataBinder.Eval(Container.DataItem, "标题") %>'  Font-Bold ="true"></asp:Label>
      </div>
     </td>
    </tr>
     <tr  class ="tr">
      <td id="tdMenuBorder">
       <div id="div" >
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
         <td>
          <div  class ="MenuBorder">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
         <tr>
         <td>
          <asp:Repeater id="rptProduct" runat="server">
           <ItemTemplate>
             <tr>
               <td style ="text-align :left; ">
                 <asp:LinkButton ID="lnkMenuDetail" runat="server" Font-Size ="small"  Font-Bold ="true"  Text ='<%# DataBinder.Eval(Container.DataItem, "标题") %>'
                    PostBackUrl ='<%# DataBinder.Eval(Container.DataItem, "src") %>'></asp:LinkButton>
                </td>
            </tr>
          </ItemTemplate>
         </asp:Repeater>
      </td>
      </tr>
     </table>
        </div>
         </td>
        </tr>
        <tr>
        <td>
          <div class ="MenuBottom" style ="height :38px"></div>
        </td>
        </tr>
        </table> 
      </div>  
     </td>
    </tr>
  </ItemTemplate>
  <FooterTemplate>
    </table>
  </FooterTemplate>
</asp:Repeater>

前台jquery

<script type="text/javascript">
$(document).ready(function(){
$("#table01 tbody td#tdManiMenu").each(function(index){
 $("#table01 tbody td#tdManiMenu:eq("+ index +")").click(function(){
   $("#table01 tbody div#div:eq("+ index +")").slideToggle("slow");
  });
 });
});

</script>

如果同时只能展开一个目录

<script type="text/javascript">
$(document).ready(function(){
var t01 = $("#table01 td#tdManiMenu").length;
var arr = new Array();
arr[0]=true;
for(i=1;i<t01;i++)
{
 $("#table01 tbody div#div:eq("+ i +")").slideToggle("slow");
arr[i]=false;
}
$("#table01 tbody td#tdManiMenu").each(function(index){
 $("#table01 tbody td#tdManiMenu:eq("+ index +")").click(function(){
    for(i=0;i<t01;i++)
    {
    if(arr[i]){   $("#table01 tbody div#div:eq("+ i +")").slideToggle("slow");arr[i]=false; }
    }
   $("#table01 tbody div#div:eq("+ index +")").slideToggle("slow");
   arr[index]=true;
  });
 });
});
</script>

后台vb

 Protected Sub rptCategories_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptCategories.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim rptProduct As Repeater = e.Item.FindControl("rptProduct")
            Dim rowv As DataRowView = e.Item.DataItem
            Dim id As String = rowv("ID")
            Dim menudetailtb As DataTable = New DataTable()
            Dim selectsql As String = "SELECT * FROM MenuDetaile where Modul='" & id & "'"
            Try
                conn.Open()
                menudetailtb = conn.GetDataTable(selectsql)
                If Not menudetailtb Is Nothing And menudetailtb.Rows.Count > 0 Then
                    rptProduct.DataSource = menudetailtb
                    rptProduct.DataBind()
                End If
            Catch ex As Exception
            Finally
                conn.Close()
            End Try
        End If
    End Sub

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值