来自代码的Div html没有显示C#

时间:2015-08-21 07:16:02

标签: c# html asp.net

我试图从后面的代码生成Accordion Pane。不知怎的,手风琴没有显示出来。我有一个Menu.aspx,它位于AccordionMenu ContentPlaceHolder中,也是一个div。在我的代码背后,我尝试用div创建手风琴窗格。以下是我的代码。

Menu.aspx

 <asp:Content ID="Content1" ContentPlaceHolderID="AccordionMenu" runat="Server">

<div id="divMenu" style="width: 241px" runat="server"></div>

代码背后

protected void Page_Load(object sender, EventArgs e)
{

    // Create Accordion Pane Header Content
    divMenu.InnerHtml = "<div class='tab_container' id='tab_container'>";

    foreach (SiteMapNode node in SiteMap.RootNode.ChildNodes)
    {
        // Header
        //Check whether is first node
        if (SiteMap.RootNode.ChildNodes.Count == 0)
        {
            // Create header html
            divMenu.InnerHtml += "<h3 class='d_active tab_drawer_heading' rel='" + node.Title + "'>" + node.Title + "</h3>";          
        }
        else
        {
            divMenu.InnerHtml += "<h3 class='tab_drawer_heading' rel='" + node.Title + "'>" + node.Title + "</h3>";
        }

        // Create header html
        divMenu.InnerHtml += "div id='" + node.Title + "' class='tab_content' style='display: block;'>";

        // Content
        foreach (SiteMapNode child in node.ChildNodes)
        {
            // Check Role Access Right
            if (CheckRolePermission(ConstantValues.MAINTENANCEMODE_VIEW, GetFunctionNameByTitle(child.Title)))
            {
                // Create content html
                divMenu.InnerHtml += "<p>" + child.Title + "</p>";
                divMenu.InnerHtml += "</div>";
            }
        }
    }

    divMenu.InnerHtml += "</div>";

}

仅限HTML - 正常工作

<table border="0" cellspacing="0" cellpadding="0" id="content-container">
    <tr>
        <td>
            <div class="tab_container" id="tab_container">
              <h3 class="d_active tab_drawer_heading" rel="tab1">Tab 1</h3>
              <div id="tab1" class="tab_content" style="display: block;">
                <p>Content 1</p>
              </div>
              <h3 class="tab_drawer_heading" rel="tab2">Tab 2</h3>
              <div id="tab2" class="tab_content" style="display: none;">
                <p>Content 2</p>
              </div>
              <h3 class="tab_drawer_heading" rel="tab3">Tab 3</h3>
              <div id="tab3" class="tab_content" style="display: none;">
                <p>Content 3</p>
              </div>
            </div>
            <script src="Menu/Js/menu.js" type="text/javascript"></script>
        </td>
        <td/>
    </tr>
</table>

1 个答案:

答案 0 :(得分:1)

你错过了div的标签。试试这个。

protected void Page_Load(object sender, EventArgs e)
{

    // Create Accordion Pane Header Content
    divMenu.InnerHtml = "<div class='tab_container' id='tab_container'>";

    foreach (SiteMapNode node in SiteMap.RootNode.ChildNodes)
    {
        // Header
        //Check whether is first node
        if (SiteMap.RootNode.ChildNodes.Count == 0)
        {
            // Create header html
            divMenu.InnerHtml += "<h3 class='d_active tab_drawer_heading' rel='" + node.Title + "'>" + node.Title + "</h3>";          
        }
        else
        {
            divMenu.InnerHtml += "<h3 class='tab_drawer_heading' rel='" + node.Title + "'>" + node.Title + "</h3>";
        }

        // Create header html
        divMenu.InnerHtml += "<div id='" + node.Title + "' class='tab_content' style='display: block;'>";

        // Content
        foreach (SiteMapNode child in node.ChildNodes)
        {
            // Check Role Access Right
            if (CheckRolePermission(ConstantValues.MAINTENANCEMODE_VIEW, GetFunctionNameByTitle(child.Title)))
            {
                // Create content html
                divMenu.InnerHtml += "<p>" + child.Title + "</p>";
            }
        }

        divMenu.InnerHtml += "</div>";
    }

    divMenu.InnerHtml += "</div>";

}