asp.net树控件

时间:2010-09-28 11:17:24

标签: asp.net treeview

我使用asp.net创建了树控件,并在标签中编写了TreeView1.SelectedNode.Value.ToString()函数来显示相应的id 但是,对于所有子节点,此处的id显示为0表示所有子节点的id显示为1 相反,我应该将父节点1的id显示为1,将父节点2的ID显示为2,依此类推 子节点也应该有唯一的id 父1的第1个子节点应该将id为第2个子节点作为2 ...

通过使用我们可以实现的功能

这是我的代码

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            

受保护的Sub TreeView1_TreeNodeCheckChanged(ByVal sender As Object,ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs)处理TreeView1.TreeNodeCheckChanged

    Label1.Text = TreeView1.SelectedNode.Value.ToString()
End Sub

在default.aspx中,我绑定了树视图

1 个答案:

答案 0 :(得分:0)

在填充树视图时为TreeNode赋值。