asp.net tree control
I have created tree control using asp.net and also written TreeView1.SelectedNode.Value.ToString()
function in label to display corresponding id
but,here id is displayed as 0 for all parent nodes for all child nodes id is displayed as 1
instead I should display parent node 1's id as 1 and parent node 2's as 2 and so on
also child node should also has unique id's
1st child node of parent 1 should have id 1,2nd child node as 2...
By using what function we can implement this
here is my code
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
Protected Sub TreeView1_TreeNodeCheckChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodeCheckChanged
Label1.Text = TreeView1.SelectedNode.Value.ToString()
End Sub
in default.aspx, i have bind the tree view
At the time of populating treeview assign value to TreeNode.
精彩评论