-1

我想写查询smn.ParentNode.ChildNodes。如果 ShowInNavigation 值为 false,我不想显示。Telerik 站点地图节点具有此属性。何做这个?

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;
        }
    }
}
4

2 回答 2

0

您可以这样做:(您不仅应该 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;
于 2013-11-08T12:36:01.433 回答
0

像这样的东西:

smn.ParentNode.ChildNodes.AsQueryable().Where(x => x.ShowInNavigation).ToList();
于 2013-01-18T15:46:39.587 回答