Home - Forums-.NET - FlyTreeView (ASP.NET) - Populate FlyTreeView with a parte of nodes

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

Populate FlyTreeView with a parte of nodes
Link Posted: 03-May-2009 23:45
I'm populating the FlyTreeView making a DataBind with my Database table:



Dim strStringaConnessione As String = myStrConnection
Dim objConn As New SqlConnection(strStringaConnessione)
Dim SQL_Legge As String = vbNullString
Dim myStrTableName As String = "myTreeView"
'        
SQL_Legge &= "SELECT IDNodo, IDPadre, Descrizione FROM " & myStrTableName
'
Dim myDataSet As New DataSet
Dim objDataAdapter As New SqlDataAdapter(SQL_Legge, objConn)
objDataAdapter.Fill(myDataSet, myStrTableName)
Dim objDataView As New DataView(myDataSet.Tables(myStrTableName))
Dim hierarchicalData As IHierarchicalEnumerable = flyTreeView.ConvertTabularDataToHierarchical(myDataSet, myStrTableName, "IDNodo", "IDPadre")

flyTreeView.DataSource = hierarchicalData
flyTreeView.DataBind()



Now I would like to extend this code to SELECT THE NODE TO SHOW IN THE TREEVIEW, for example setting the nodes by its "IDNodo" and populate the FlyTreeView whith this node and all its childe node (and ONLY this one).

If I modify the Select Query, adding this filter it doesen't work:


Dim StartFolder as Integer = 261
SQL_Legge &= "SELECT IDNodo, IDPadre, Descrizione FROM " & myStrTableName & " "
SQL_Legge &= "WHERE IDNodo = " & StartFolder


Is there a way to solve the problem?

THANK YOU.
igor
Link Posted: 04-May-2009 00:15
So what you need is to filter data from your table.
The only requirement to you data source is that it should contain at least one node with IDPadre = IDNodo or IDPadre = null (defined for root nodes). Do you have such nodes when filter data from table?
Link Posted: 04-May-2009 00:51
Hi Evgeny, thanks for your replay.
Ok I have understood the problem.

I extract my data whit this filter:


SQL_Legge &= "SELECT IDNodo, IDPadre, Descrizione FROM " & TreeViewTableName & " "
SQL_Legge &= "WHERE "
SQL_Legge &= "IDNodo = " & StartFolder & " "
SQL_Legge &= "OR "
SQL_Legge &= "IDPadre = " & ChildeFiles & " "


and then I need to "manually" modify the dataset in order to change the IDPadre of the StartFolder to be null (or equal to IDPadre), because of these are sub-sub-sub folder... so...
Link Posted: 04-May-2009 00:57
I think you can do this in select, using CASE WHEN statement:
(CASE WHEN IDPadre = ''somevalueforidpadre' THEN NULL ELSE IDPadre END) AS IDPadre

Or smth like this.
Link Posted: 04-May-2009 02:43
This is a very good idea!
I will try this way.
Link Posted: 04-May-2009 04:00
Ok I have solved with this (post my solution for the forum):


                SQL_Legge &= "SELECT IDNodo, Descrizione, "
                SQL_Legge &= "(CASE "
                SQL_Legge &= "WHEN IDNodo = " & StartFolder & " THEN NULL "
                SQL_Legge &= "ELSE " & StartFolder & " "
                SQL_Legge &= "END) AS IDPadre "
                SQL_Legge &= "FROM " & TreeViewTableName & " "
                SQL_Legge &= "WHERE "
                SQL_Legge &= "IDNodo = " & StartFolder & " "
                SQL_Legge &= "OR "
                SQL_Legge &= "IDPadre = " & ChildeFiles & " "


THANKS A LOT.
Igor