ho creato questo codice per caricare un treeview(modificando il codice natio microsoft) da un database.
Vista la complessità dell'albero volevo caricare solo la parte di albero che veniva visualizzata, quindi, sempre seguendo le indicazioni Microsoft ho gestito il codice che mi indicava l'MSDN.
il fatto è che non funziona..
qualcuno vede se c'è qualcosa di palesemente sbagliato nel codice che segue??
grazie
in anticipo
Nick
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
'Inserire qui il codice utente necessario per inizializzare la pagina
Dim nodeSupp, nodeProd As TreeNode
Dim strConString As String
Dim conn As SqlConnection
Dim cmdSelect As SqlCommand
Dim ds As SqlDataReader
Dim i As Integer
Dim dl, dc As Date
Dim SezioneOld As String
Dim NodeArray(10) As TreeNode
' 0 root
' 1 Livello Anno
' 2 Livello Data
' 3 Livello Sezione
' 4 Livello Articolo
strConString = ConfigurationSettings.AppSettings("conString")
conn = New SqlConnection(strConString)
cmdSelect = New SqlCommand("select * from Q_StrutturaIndice", conn)
conn.Open()
NodeArray(0) = New TreeNode
NodeArray(0).Text = "La Guida di Cuneo"
NodeArray(0).Expandable = ExpandableValue.CheckOnce
IndiceGerarchico.Nodes.Add(NodeArray(0))
ds = cmdSelect.ExecuteReader()
While ds.Read()
dc = ds.GetDateTime(0)
If dc <> dl Then
' Verifico per cambio anno
If dc.Year() <> dl.Year() Then
' Cambio Anno
NodeArray(1) = New TreeNode
NodeArray(1).Text = Str(dc.Year)
NodeArray(1).Expandable = ExpandableValue.CheckOnce
NodeArray(0).Nodes.Add(NodeArray(1))
End If
' Cambio data
NodeArray(2) = New TreeNode
NodeArray(2).Text = dc.ToShortDateString()
NodeArray(2).Expandable = ExpandableValue.CheckOnce
NodeArray(1).Nodes.Add(NodeArray(2))
dl = dc
SezioneOld = ""
End If
If ds.GetString(1) <> SezioneOld Then
' Cambio Sezione
NodeArray(3) = New TreeNode
NodeArray(3).Text = ds.GetString(1)
NodeArray(3).Expandable = ExpandableValue.CheckOnce
NodeArray(2).Nodes.Add(NodeArray(3))
SezioneOld = ds.GetString(1)
End If
NodeArray(4) = New TreeNode
NodeArray(4).Text = ds.GetString(2)
NodeArray(4).Target = "main"
NodeArray(4).NavigateUrl = "BrowserArticolo.aspx?Edizione=" & ds.GetString(3) & "&Pagina=" & ds.GetString(4) & "&Articolo=" & ds.GetString(5)
NodeArray(4).Expandable = ExpandableValue.CheckOnce
NodeArray(3).Nodes.Add(NodeArray(4))
'Exit While
End While
ds.Close()
conn.Close()
End If
End Sub
Private Sub IndiceGerarchico_Collapse(ByVal sender As Object, ByVal e As _
Microsoft.Web.UI.WebControls.TreeViewClickEventArg s) _
Handles IndiceGerarchico.Collapse
Dim nodeAuthor As TreeNode
nodeAuthor = sender.nodes(e.Node.ToString)
If nodeAuthor.Nodes.Count > 0 Then
nodeAuthor.Nodes.Clear()
nodeAuthor.Expandable = ExpandableValue.Always
End If
End Sub