我已經使用asp.net創建了樹形控件,並且在標籤中寫入了TreeView1.SelectedNode.Value.ToString()
函數來顯示相應的ID 但是,此處的id對於所有子節點的所有父節點都顯示爲0 id顯示爲1 相反,我應該顯示父節點1的id爲1,父節點2的爲2等等 還應該有子節點的唯一id's 父節點1的第一個子節點應該有id爲1,2的子節點爲2 ...asp.net樹形控件
使用什麼功能,我們可以在這裏實現這個
是我的代碼
default.aspx.vb
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim conectionstring As String
conectionstring = "USER ID=sa;PASSWORD=welcome3#;SERVER=PC325;Initial catalog=login"
Dim SQLQuery As String = "Select * from tblEmp"
Dim MyConn As New SqlClient.SqlConnection(conectionstring)
Dim dataset As DataSet = New DataSet()
Dim Cmd As New SqlClient.SqlDataAdapter(SQLQuery, MyConn)
Cmd.Fill(dataset, "Employee")
'Fill the TreeView control Nodes using For Loop
For Each Row As DataRow In dataset.Tables("Employee").Rows
Dim TNode As New TreeNode()
TNode.Value = Row("empCode")
TNode.Text = Row("empName")
TNode.ShowCheckBox = True
TNode.Selected.ToString()
TreeView1.Nodes.Add(TNode)
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim conectionstring As String
conectionstring = "USER ID=sa;PASSWORD=welcome3#;SERVER=PC325;Initial catalog=login"
Dim SQLQuery As String = "Select * from tblEmp"
Dim MyConn As New SqlClient.SqlConnection(conectionstring)
Dim dataset As DataSet = New DataSet()
Dim Cmd As New SqlClient.SqlDataAdapter(SQLQuery, MyConn)
Cmd.Fill(dataset, "uw")
'Fill the TreeView control Nodes using For Loop
For Each Row As DataRow In dataset.Tables("uw").Rows
Dim TNode As New TreeNode()
TNode.Value = Row("username")
TNode.Text = Row("pasword")
TNode.Selected.ToString()
TreeView1.Nodes.Add(TNode)
Dim CNode1 As New TreeNode(Row("username"))
TNode.ChildNodes.Add(CNode1)
Dim CNode2 As New TreeNode(Row("fullname"))
TNode.ChildNodes.Add(CNode2)
Dim CNode3 As New TreeNode(Row("pasword"))
TNode.ChildNodes.Add(CNode3)
TNode.CollapseAll()
Next
End If
End Sub
保護的子TreeView1_TreeNodeCheckChanged(BYVAL發件人爲對象,BYVALË作爲System.Web.UI.WebControls.TreeNodeEventArgs)把手TreeView1.TreeNodeCheckChanged
Label1.Text = TreeView1.SelectedNode.Value.ToString()
End Sub
在默認的.aspx,我已樹視圖
您definetly需要,以獲得提供源代碼的進一步幫助 – citronas 2010-09-28 12:41:47