【原创】umbraco 用户控件生成内容列表

 

本文的目的是说明如何使用用户控件读取umbraco的content,自动生成内容的链接列表。

即从(图一)生成(图二)的内容

            (图一)

                (图二)

 

应用场景:内容管理员发布的文章,会自动在网上首页上生成文章的连接,节省了工作量,降低的对内容管理员的技术要求。

 

用户控件的代码如下:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.presentation.nodeFactory;

namespace buildlist
{
public partial class buildlist : System.Web.UI.UserControl
{

protected void Page_Load(object sender, EventArgs e)
{

//If you just want the children of the current node use the following method
Node currentNode = Node.GetCurrent();
//If you need a specific node based on ID use this method (where 123 = the desired node id)
// var specificNode = new Node(123);
//To get the children as a Nodes collection use this method
Nodes childNodes = currentNode.Children;
//Iterating over nodes collection example
Response.Write("<div class='news'>");
foreach(Node node in childNodes)
{

Response.Write(string.Format("<a href='" + node.Url + "'target=_blank>{0}</a><br />", node.Name));
}
Response.Write("</div>");

}
}
}

如何将用户控件添加到umbraco中,,可以看官方的视频教程:http://umbraco.com/help-and-support/video-tutorials/introduction-to-umbraco/developer-introduction/using-net-user-controls/TVPlayer

注意:使用.net3.5编译。

posted on 2012-03-16 16:27  e凭可乐  阅读(362)  评论(1编辑  收藏  举报