日期:2014-05-20 浏览次数:20776 次
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
IList<Area> list = new List<Area>();
list.Add(new Area() { Uid=1, Pid=0, Name="电信" });
list.Add(new Area() { Uid=2, Pid=0, Name="联通" });
list.Add(new Area() { Uid=3, Pid=0, Name="移动" });
list.Add(new Area() { Uid=4, Pid=1, Name="电信一区" });
list.Add(new Area() { Uid=5, Pid=1, Name="电信二区" });
// 用linq查询得到 uid、name
// name中显示父级-子级-子子级。。。。,只要最后一级
// 结果:
//uid name
//2 联通
//3 移动
//4 电信-电信一区
//5 电信-电信二区
}
}
public class Area
{
public int Uid { get; set; }
public int Pid { get; set; }// 父ID
public string Name { get; set; }
}
void Main()
{
IList<Area> list = new List<Area>();
list.Add(new Area() { Uid=1, Pid=0, Name="电信" });
list.Add(new Area() { Uid=2, Pid=0, Name="联通" });
list.Add(new Area() { Uid=3, Pid=0, Name="移动" });
list.Add(new Area() { Uid=4, Pid=1, Name="电信一区" });
list.Add(new Area() { Uid=5, Pid=1, Name="电信二区" });
var query=from l in list