梅の雪の木2.0とテスト例

2837 ワード

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title> </title>
    <script type="text/javascript" src="scripts/jsframework.js"></script>   
</head>
<body>
    <form id="form1" runat="server">
    <script type="text/javascript" language="javascript">
        var data={};
        data["-1_0"] = "text:  ;";

        <% LoadTree();%>       
       //*
        Using("System.Web.UI.WebControls.MzTreeView");
        var a = new MzTreeView();
        a.dataSource = data
     
        a.autoSort=false;
       // a.useCheckbox=true
        a.canOperate=true;
        document.write(a.render());
        a.expandLevel(1);
        //*/
    </script>   
    </form>
</body>
</html>
--------------------------------------------------------------------------------
 public void LoadTree()
    {
        string nodes = "";
        DataTable dt = bind();

        foreach (DataRow dr in dt.Rows)
        {
            nodes = " /r/n data[/'" + dr["pid"].ToString() + "_" + dr["id"].ToString() + "/'] = /'text:" + dr["name"].ToString() + ";url:" + dr["url"].ToString() + "/';/r/n";
            Response.Write(nodes);
        }
    }
    DataTable bind()
    {
        DataTable dt = new DataTable();
        DataRow dr;
        dt.Columns.Add(new DataColumn("id", typeof(Int32)));
        dt.Columns.Add(new DataColumn("pid", typeof(Int32)));
        dt.Columns.Add(new DataColumn("name", typeof(String)));
        dt.Columns.Add(new DataColumn("url", typeof(String)));

        dr = dt.NewRow();
        dr[0] = 1;
        dr[1] = 0;
        dr[2] = " ";
        dr[3] = "test1.aspx";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        dr[0] = 2;
        dr[1] = 1;
        dr[2] = " ";
        dr[3] = "test2.aspx";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        dr[0] = 3;
        dr[1] = 1;
        dr[2] = " ";
        dr[3] = "test3.aspx";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        dr[0] = 4;
        dr[1] = 0;
        dr[2] = "WEB ";
        dr[3] = "test4.aspx";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        dr[0] = 5;
        dr[1] = 4;
        dr[2] = "ASP.NET";
        dr[3] = "test5.aspx";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        dr[0] = 6;
        dr[1] = 2;
        dr[2] = " ";
        dr[3] = "test6.aspx";
        dt.Rows.Add(dr);

        return dt;
    }