Code
protected void Page_Load(object sender, EventArgs e)
{
IList<UserInfo> listUsers = new List<UserInfo>();
UserInfo objUser = new UserInfo();
objUser.Name = "TestUser1";
objUser.Sex = "M";
objUser.City = "ShenZhen";
listUsers.Add(objUser);
objUser = new UserInfo();
objUser.Name = "TestUser2";
objUser.Sex = "F";
objUser.City = "BeiJing";
listUsers.Add(objUser);
objUser = new UserInfo();
objUser.Name = "TestUser3";
objUser.Sex = "M";
objUser.City = "USA";
listUsers.Add(objUser);
System.Text.StringBuilder builder = new System.Text.StringBuilder();
builder.Append("#foreach($u in $ListUsers)\r\n" +
"#beforeall\r\nssssssssssssssssssssssssssssssss" +
"<table border=\"0\" cellpadding=\"10\" cellspacing=\"10\">" +
"<tr><td>Name</td><td>Sex</td><td>City</td></tr>" +
"#each\r\n" +
"<tr>" +
"<td>" + nono("$u.Name")+ "</td>" + ////////调用处
"<td>$u.Sex</td>" +
"<td>$u.City</td>" +
"</tr>" +
"#afterall\r\n" +
"</table>" +
"#nodata\r\n" +
"暂无用户资料\r\n" +
"#end");
VelocityEngine vltEngine = new VelocityEngine();
vltEngine.Init();
VelocityContext vltContext = new VelocityContext();
vltContext.Put("PageTitle", "字符串模板例子");
vltContext.Put("ListUsers", listUsers);
System.IO.StringWriter vltWriter = new System.IO.StringWriter();
vltEngine.Evaluate(vltContext, vltWriter, null, builder.ToString());
Response.Write(vltWriter.GetStringBuilder().ToString());
}
//方法名
public string nono(string dd)
{
return dd;
}
protected void Page_Load(object sender, EventArgs e)
{
IList<UserInfo> listUsers = new List<UserInfo>();
UserInfo objUser = new UserInfo();
objUser.Name = "TestUser1";
objUser.Sex = "M";
objUser.City = "ShenZhen";
listUsers.Add(objUser);
objUser = new UserInfo();
objUser.Name = "TestUser2";
objUser.Sex = "F";
objUser.City = "BeiJing";
listUsers.Add(objUser);
objUser = new UserInfo();
objUser.Name = "TestUser3";
objUser.Sex = "M";
objUser.City = "USA";
listUsers.Add(objUser);
System.Text.StringBuilder builder = new System.Text.StringBuilder();
builder.Append("#foreach($u in $ListUsers)\r\n" +
"#beforeall\r\nssssssssssssssssssssssssssssssss" +
"<table border=\"0\" cellpadding=\"10\" cellspacing=\"10\">" +
"<tr><td>Name</td><td>Sex</td><td>City</td></tr>" +
"#each\r\n" +
"<tr>" +
"<td>" + nono("$u.Name")+ "</td>" + ////////调用处
"<td>$u.Sex</td>" +
"<td>$u.City</td>" +
"</tr>" +
"#afterall\r\n" +
"</table>" +
"#nodata\r\n" +
"暂无用户资料\r\n" +
"#end");
VelocityEngine vltEngine = new VelocityEngine();
vltEngine.Init();
VelocityContext vltContext = new VelocityContext();
vltContext.Put("PageTitle", "字符串模板例子");
vltContext.Put("ListUsers", listUsers);
System.IO.StringWriter vltWriter = new System.IO.StringWriter();
vltEngine.Evaluate(vltContext, vltWriter, null, builder.ToString());
Response.Write(vltWriter.GetStringBuilder().ToString());
}
//方法名
public string nono(string dd)
{
return dd;
}