zoukankan      html  css  js  c++  java
  • Accordion动态添加AccordionPane

    代码
    <%@ Control Language="C#" AutoEventWireup="true" Codebehind="Menu.ascx.cs" Inherits="Web.Controls.Menu" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
    <div style=" 100%; text-align: left;">
    <ajaxToolkit:Accordion ID="MyAccordion" runat="Server" SelectedIndex="0" HeaderCssClass="accordionHeader"
    HeaderSelectedCssClass
    ="accordionHeaderSelected" ContentCssClass="accordionContent"
    AutoSize
    ="None" FadeTransitions="true" TransitionDuration="250" FramesPerSecond="40"
    RequireOpenedPane
    ="false" SuppressHeaderPostbacks="true">
    <Panes>
    </Panes>
    <HeaderTemplate>
    <div style=" 150px; height: 35px; color: White; background-image: url('<%=ResolveClientUrl("~/Images") %>/Slice1.png');">
    <div style="padding-top: 10px; padding-left:10px; font-weight:bold; font-size:12px;">
    <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
    </div>
    </div>
    </HeaderTemplate>
    <ContentTemplate>
    <div style=" 150px; height: auto; line-height: 25px; background-color: #748CCF;
    text-align: left;"
    >
    <div style="margin-left: 20px; color: White;">
    <asp:PlaceHolder ID="PlaceHolder2" runat="server"></asp:PlaceHolder>
    </div>
    </div>
    </ContentTemplate>
    </ajaxToolkit:Accordion>
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
    </div>
    代码
    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;

    namespace Web.Controls
    {
    public partial class Menu : System.Web.UI.UserControl
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    CreatMenu();
    }

    void CreatMenu()
    {
    int count = 1;
    foreach (SiteMapNode group in SiteMap.RootNode.ChildNodes)
    {

    AjaxControlToolkit.AccordionPane ap
    = new AjaxControlToolkit.AccordionPane();
    ap.Header
    = MyAccordion.HeaderTemplate;
    ap.Content
    = MyAccordion.ContentTemplate;
    HyperLink hl
    = new HyperLink();
    hl.Text
    = group.Title;
    hl.Target
    = group.Url;
    foreach (Control c in ap.HeaderContainer.Controls)
    {
    if (c.GetType().Name == "PlaceHolder")
    {
    c.Controls.Add(hl);
    break;
    }
    }

    foreach (SiteMapNode child in group.ChildNodes)
    {
    HyperLink hl2
    = new HyperLink();
    hl2.Text
    = child.Title;
    hl2.Target
    = child.Url;
    foreach (Control c in ap.ContentContainer.Controls)
    {
    if (c.GetType().Name == "PlaceHolder")
    {
    c.Controls.Add(hl2);
    break;
    }
    }
    }
    count
    ++;
    MyAccordion.Panes.Add(ap);
    }
    }
    }
    }
  • 相关阅读:
    cron表达式详解
    C# Quartz 调度任务辅助类
    SQLserver查询用逗号隔开的字段中是否包含另一个字段的值
    c# 将字符串转换为逻辑表达式(字符串转换布尔)
    铺砖块
    字符串涂漆
    快餐店
    乘号加号
    传纸条(lgP1006)
    小明的喷漆计划
  • 原文地址:https://www.cnblogs.com/yym/p/1670983.html
Copyright © 2011-2022 走看看