NVelocity 主從表

來源:互聯網
上載者:User

經常來部落格園找資料。今天也發布一點點原創。

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using NVelocityTemplateEngine;
using NVelocityTemplateEngine.Interfaces;
using System.Collections.Generic;
namespace DianXin.UserWeb
{
    public partial class wei9931_MasterSalver : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(ProcessFileTemplate());
        }

        private string ProcessFileTemplate()
        {
           
            IList<user_slave> user_slave10 = new List<user_slave>();
            user_slave temp_10 = new user_slave(10,"語文1");
            user_slave10.Add(temp_10);
            user_slave temp_11 = new user_slave(10, "數學1");
            user_slave10.Add(temp_11);

            IList<user> users = new List<user>();
            user user1=new user(10,"wei9931",user_slave10);
            users.Add(user1);

 

            IList<user_slave> user_slave20 = new List<user_slave>();
            user_slave temp_20 = new user_slave(20, "語文2");
            user_slave20.Add(temp_20);
            user_slave temp_21 = new user_slave(20, "數學2");
            user_slave20.Add(temp_21);           
            user user2 = new user(20, "baidu.com",user_slave20);
            users.Add(user2);

 

 

            IList<user_slave> user_slave30 = new List<user_slave>();
            user_slave temp_30 = new user_slave(30, "語文3");
            user_slave30.Add(temp_30);
            user_slave temp_31 = new user_slave(30, "數學3");
            user_slave30.Add(temp_31);           
            user user3 = new user(30, "baidu.com",user_slave30);
            users.Add(user3);

 

 

           
            string templateDir = HttpContext.Current.Server.MapPath("template");
            string templateName = "wei9931_masterslaver.vm";
            INVelocityEngine fileEngine =            NVelocityEngineFactory.CreateNVelocityFileEngine(templateDir, true);
            IDictionary context = new Hashtable();
            context.Add("arrayList", users);
            return fileEngine.Process(context, templateName);
        }

        public class user_slave
        {
            private int id;
            private string studentclass;
            public int Id
            {
                set { id = value; }
                get { return id; }
            }
            public string Studentclass
            {
                set { studentclass = value; }
                get { return studentclass; }
            }
            public user_slave(int id, string studentclass)
            {
                this.id = id;
                this.studentclass = studentclass;
            }

        }

        public class user
        {

            private string name;
            private int id;
            private IList<user_slave> user_slave_tab;

            public IList<user_slave> User_slave_tab
            {
                set { this.user_slave_tab = value; }
                get { return user_slave_tab; }
            }

            public string Name
            {
                set { name = value; }
                get { return name; }
            }
            public int Id
            {
                set { id = value; }
                get { return id; }
            }
            public user(int id, string name, IList<user_slave> user_slave_tabs)
            {
                this.name = name;
                this.id = id;
                this.user_slave_tab = user_slave_tabs;
            }

        }
       

    }
}

 

 

以下是模板檔案:

_____________________________________________________________________________

<table border="1">
 
  #foreach ( $customer in $arrayList )           
  <tr>  <td>$customer.name</td>
    <td>
        <table border="1">
          <tr>
            #foreach( $selection in $customer.User_slave_tab )
            <td>$selection.studentclass</td>          
              #end
          </tr>   
        </table>
    </td>
  </tr>
    #end
 
</table>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.