从vb.net中的treeview获取已检查的节点值

时间:2015-04-27 03:20:28

标签: asp.net vb.net treeview

我有一个从数据库中获取的树视图。问题是我不明白一旦用户检查节点后如何获取值。这是代码。

 <td>
                                    <asp:TreeView ID="treeCountry" runat="server" NodeIndent="10" ShowCheckBoxes="All">
                                    <ParentNodeStyle Font-Bold="False" />
                                    <HoverNodeStyle Font-Underline="True" />
                                    <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px" />
                                    <NodeStyle Font-Names="Arial" Font-Size="10pt" ForeColor="Black" HorizontalPadding="5px"
                                        NodeSpacing="0px" VerticalPadding="0px" />
                                </asp:TreeView>
                                </td>

但我不知道在用户检查节点时如何获取值。谁能帮帮我吗。这是vb.net编码

 cmd.CommandText = "SELECT CountryName, CountryCode FROM tblCountry "
        rs = cmd.ExecuteReader

        If rs.HasRows Then
            While rs.Read
                Dim tnNew As New TreeNode
                tnNew.Text = CType(rs("CountryName"), String)
                tnNew.Value = CType(rs("CountryID"), String)
                treeCountry.Nodes.Add(tnNew)

                Try
                    collMenu.Add(tnNew, CType(rs("CountryID"), String))
                Catch ex As Exception
                End Try

            End While
        End If
        rs.Close()

        cmd.CommandText = "SELECT AreaName, AreaID, countryID FROM tblArea"
        rs = cmd.ExecuteReader

        If rs.HasRows Then
            While rs.Read
                Try
                    Dim tnNew As New TreeNode

                    tnNew.Text = CType(rs("AreaName), String)
                    tnNew.Value = CType(rs("AreaID"), String)
                    tnParent = CType(collMenu.Item(CType(rs("countryID"), String)), TreeNode)
                    tnParent.ChildNodes.Add(tnNew)
                    collMenu.Add(tnNew, CType(rs("AreaID"), String))
                Catch ex As Exception
                End Try
            End While
        End If

        rs.Close()

0 个答案:

没有答案