0

特定の Treeview 内のすべてのノード ID を返すのに苦労しています。

基本的に、特定の NodeID を使用してデータベースにクエリを実行し、以下に示すようにその親ノード ID を返す関数があります。これは正常に機能し、渡されたノード ID の親ノード ID を返します。

public static string Parent_ID(string NodeID)
{        
   GeneralConnection gc = ConnectionHelper.GetConnection();
   int intNodeID = Convert.ToInt32(NodeID);

   QueryDataParameters para = new QueryDataParameters();
   para.Add("@NodeID", intNodeID);

   int parent = (int)gc.ExecuteScalar("custom.product.searchForParentNodeID", para);

   return Convert.ToString(parent);              
}

返される ParentID は、実際には上記の Node の NodeID です。したがって、基本的には、新しく取得した ID を使用してその ParentID を取得し、現在のレベル内のすべての NodeID を取得できるまで、(上記のクエリを使用して) テーブルをループし続けます。明らかに、これらの NodeID を StringBuilder リストに格納し、それをさらにチェックするために使用する予定です。

誰にも提案がありますか?

4

1 に答える 1

2

あなたの質問は少し混乱していますが、これが役立つかもしれません。可能であれば、カスタム クエリの代わりに API を使用して、将来の修正プログラムやアップグレードを容易にすることをお勧めします。たとえば、ノード ID があり、そのすべての兄弟が必要な場合は、次のようにすることができます。

// Version 7 code, untested
var treeProvider = new TreeProvider();
var childNodeId = 1;

// Get the child Node
// Node ID, Culture, Site name
var childNodeDataSet = treeProvider.SelectNodes(childNodeId, null, CMSContext.CurrentSiteName);

if (childNodeDataSet.Items.Any())
{
    // Assuming the child node was found, get the parent ID
    var parentNodeId = childNodeDataSet.Items[0].NodeParentID;

    // Now get the children of the parent, aka the siblings
    // Site name, Culture, Combine with default culture, Where clause, Order by clause
    var siblingNodes = treeProvider.SelectNodes(CMSContext.CurrentSiteName, "/%", null, false, null, "NodeParentID = '" + parentNodeId + "'", null);
}

それが役立つことを願っています。

于 2013-09-04T13:31:21.123 に答える