二级Accordion控件的用法

aspx页面:

<asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
           
            <ajax:Accordion runat="server" ID="accordion" FadeTransitions="false" RequireOpenedPane="true" AutoSize="None" CssClass="accordion" HeaderCssClass="header" ContentCssClass="content" Height="100%">
          
            </ajax:Accordion>

 

aspx.cs页面:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Common;
using yueue.ADOKeycap;
using RGPWEB;
using System.Data.SqlClient;
using System.Data;
using System.Web.UI.HtmlControls;
public partial class Web_MainLeft : System.Web.UI.Page
{
    private DataTable ModuleTable;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!SessionBox.CheckUserSession())
        {
            Response.Redirect("~/login.aspx");
        }
        else
        {
            if (!IsPostBack)
            {
                try
                {
                    InitTopMenu();
                }
                catch
                {
                   // MenuTreeView.Nodes.Clear();
                }
            }
        }
    }

    private void InitTopMenu()  //添加一级菜单
    {
        RGP.BLL.RGP_Modules bll = new RGP.BLL.RGP_Modules();
       
        ModuleTable = bll.GetModuleTypeList("").Tables[0];  //取得所有数据得到DataTable
        int i = 0;
        foreach (DataRow dr in ModuleTable.Rows)
        {
            //创建折叠面板对象
            AjaxControlToolkit.AccordionPane p = new AjaxControlToolkit.AccordionPane();

            //为折叠面板创建ID
            p.ID = "AccordionPane_" + i.ToString();

            //将标题加入折叠面板头部
            //Label lab = new Label();
            //lab.ID = dr["ModuleTypeID"].ToString();
            //lab.Text = dr["ModuleTypeName"].ToString();
            HtmlGenericControl htg = new HtmlGenericControl();
            htg.InnerHtml = "<font color=#000000 align=center> " + dr["ModuleTypeName"].ToString() + "</font>";
                             
            p.HeaderContainer.Controls.Add(htg);
            InitSecondMenu(dr["ModuleTypeID"].ToString(), p);
            accordion.Panes.Add(p);
            i++;
            /**/
            /*
    您自己的取标题链接的数据库内容的代码
*/
        }

        //MenuTreeView.Target = "tabWin";
    }

    private void InitSecondMenu(string ModuleTypeID,AjaxControlToolkit.AccordionPane p) //添加二级菜单
    {
        RGP.BLL.RGP_Modules bll = new RGP.BLL.RGP_Modules();
                DataSet Module = bll.GetModuleList("ModuleTypeID=" + ModuleTypeID);
                int i = 0;
                string strHtml = "";
                HtmlGenericControl htg = new HtmlGenericControl();
                htg.InnerHtml = "";
                //ListView view=new ListView();
                //view.ID = "View_" + ModuleTypeID;
               
                //view.DataSource = Module.Tables[0];
                //view.DataBind();

                foreach (DataRow child_dr in Module.Tables[0].Rows)
                {
                    ////Label lab = new Label();
                    ////LinkButton lab = new LinkButton();
                    ////lab.ID = child_dr["ModuleID"].ToString();
                    ////lab.Text = child_dr["ModuleName"].ToString();
                  
                    ////p.ContentContainer.Controls.Add(lab);
                    //ListItem li = new ListItem();
                    //li.Value = child_dr["ModuleID"].ToString();
                    //li.Text = child_dr["ModuleName"].ToString();
                    //view.InsertItem.Controls.Add(li);
                    strHtml +="<li><a href='"+child_dr["ModuleURL"].ToString()+"' target='tabWin'>"+child_dr["ModuleName"].ToString()+"</a></li>";
                }
                htg.InnerHtml = "<ul>" + strHtml + "</ul>";
                p.ContentContainer.Controls.Add(htg);

    }
    
}

 

 

 

你可能感兴趣的:(accordion)