日期:2014-05-17  浏览次数:20478 次

|zyciis| 如何在aspx文件中写及时代码输出菜单事,谢谢 急
如CS:
C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected List<Menu> MenuList = new List<Menu>();
    protected void Page_Load(object sender, EventArgs e)
    {
        MenuList.Add(new Menu() { ID = 1, ParentID = 0, Name = "文件" });
        MenuList.Add(new Menu() { ID = 2, ParentID = 0, Name = "编辑" });
        MenuList.Add(new Menu() { ID = 3, ParentID = 1, Name = "新建" });
        MenuList.Add(new Menu() { ID = 4, ParentID = 2, Name = "撤消" });
        MenuList.Add(new Menu() { ID = 5, ParentID = 3, Name = "项目" });
        MenuList.Add(new Menu() { ID = 6, ParentID = 1, Name = "打开" });
    }
}
public class Menu
{
    public int ID { get; set; }
    public int ParentID { get; set; }
    public string Name { get; set; }
}


然后要在aspx中输出如下HTML
HTML code

<!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>
    <title></title>
</head>
<body>
    <ul>
        <li>文件
            <ul>
                <li>新建
                    <ul>
                        <li>项目</li>
                    </ul>
                </li>
                <li>打开 </li>
            </ul>
        </li>
        <li>编辑
            <ul>
                <li>撤消</li>
            </ul>
        </li>
    </ul>
</body>
</html>


那么ASPX文件
HTML code

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

<!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>
    <title></title>
</head>
<body>
    <%
        for (int i = 0; i <= MenuList.Count - 1; i++)
        { 
        }
        //??这里应该如何来输出上面的那个菜单事呢?
        //谢谢
    %>
</body>
</html>



------解决方案--------------------
构建字符串
StringBuilder sb=new StringBuilder();
for (int i = 0; i <= MenuList.Count - 1; i++)


}
根据ParentID 查询子集
或使用repeater在模板列输出数据
------解决方案--------------------
你之前问过吧 

我记得我还写过代码