views:

25

answers:

1

hi, i hav created tree control using asp.net..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 hav 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

A: 

At the time of populating treeview assign value to TreeNode.

Jeevan Bhatt
how to populate in tree view...i used simple concepts to create tree.. just view the data in tree from a database's table...plz explain me in clear...i can't get u
patri
suppose you have an object "objCountries" collection of a class and u want to populate treeView so your code will be TreeNode node;foreach(object obj in objCountries){ node=new TreeNode(); node.Text=obj.Country; node.Value = obj.CountryID; treeViewControl.Nodes.Add(node); } and if u have nested node then put code in a function and do recursion....
Jeevan Bhatt
i need to implement multi tree view in asp.net...like that of browsing for a folder in windows...plz give some codes.. tell me whether there are any downloadable controls in any sites
patri