write linq query sitemapnode
本文关键字:sitemapnode query linq write | 更新日期: 2023-09-27 17:54:28
我想写查询smn.ParentNode.ChildNodes
。如果ShowInNavigation值为false,我不想显示。teleerik站点地图节点有这个att。怎么做?
using System;
using System.Web;
using Telerik.Sitefinity.Web;
using System.Linq;
using System.Data;
public partial class CustomTemplate_Navigation : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
SiteMapNode smn = SiteMapBase.GetCurrentProvider().CurrentNode;
while (smn.ParentNode != null)
{
if (smn.ParentNode.ParentNode == SiteMap.RootNode)
{
siteMapControl_verticaltree.DataSource = smn.ParentNode.ChildNodes;/*this line will be write query*/
siteMapControl_verticaltree.DataBind();
break;
}
smn = smn.ParentNode;
}
}
}
像这样:
smn.ParentNode.ChildNodes.AsQueryable().Where(x => x.ShowInNavigation).ToList();
您可以这样做:(您不仅应该Linqify,而且还需要强制转换)(我在一个。net MVC4项目中使用了这个)
SiteMapNodeCollection coll = SiteMap.RootNode.ChildNodes;
IEnumerable<SiteMapNode> nodes = coll.Cast<SiteMapNode>();
var query = from node in nodes where Boolean.Parse(node["ShowInNavigation"]) == true select node;