1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| Imports System.Data.SqlClient
Imports System.Data
Partial Class qualification
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
PopulateRootLevel()
End If
End Sub
Private Sub PopulateRootLevel()
Dim objConn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("ChaineConnection").ConnectionString)
Dim objCommand As New SqlCommand("select idQualification, libelle, (select count(*) FROM qualificationLibelle qL WHERE idParent=qL.idQualification) childnodecount FROM qualificationLibelle WHERE idParent IS NULL", objConn)
Dim da As New SqlDataAdapter(objCommand)
Dim dt As New DataTable()
da.Fill(dt)
PopulateNodes(dt, TreeView1.Nodes)
End Sub
Private Sub PopulateSubLevel(ByVal idParent As Integer, ByVal parentNode As TreeNode)
Dim objConn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("ChaineConnection").ConnectionString)
Dim objCommand As New SqlCommand("select idQualification, libelle, (select count(*) FROM qualificationLibelle qL WHERE idParent=qL.idQualification) childnodecount FROM qualificationLibelle WHERE idParent=@idParent", objConn)
objCommand.Parameters.Add("@idParent", SqlDbType.Int).Value = idParent
Dim da As New SqlDataAdapter(objCommand)
Dim dt As New DataTable()
da.Fill(dt)
PopulateNodes(dt, parentNode.ChildNodes)
End Sub
Private Sub PopulateNodes(ByVal dt As DataTable, ByVal nodes As TreeNodeCollection)
For Each dr As DataRow In dt.Rows
Dim tn As New TreeNode()
tn.Text = dr("libelle").ToString()
tn.Value = dr("idQualification").ToString()
nodes.Add(tn)
'If node has child nodes, then enable on-demand populating
tn.PopulateOnDemand = (CInt(dr("childnodecount")) > 0)
Next
End Sub
Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate
PopulateSubLevel(CInt(e.Node.Value), e.Node)
End Sub
End Class |
Partager