Treeview SelectedNodeChanged fires for only....
-
hi, I have codebelow to populate treeview it works fine & binds value & text to nodes perfectly, I want to set background for selected nodes & get pathvalue of selected nodes I tried to put code inside TvFile_SelectedNodeChanged but it fires only for root node. it doenst fire for any other node.please help me to get selected node value please help me out, code Partial Class FileApplication Inherits System.Web.UI.Page Private Const VirtualImageRoot As String = "~/FileFolder/" Private ClsFileapp As New TreeFileApplication Private GetCurId As String = String.Empty Private ds As DataSet Private Sub PopulateTree() Dim rootFolder As New DirectoryInfo(Server.MapPath(VirtualImageRoot)) Dim root As TreeNode = AddNodeAndDescendent(0, Nothing) TvFile.Nodes.Add(root) End Sub Private Function AddNodeAndDescendent(ByVal val As Integer, ByVal parentNode As TreeNode) As TreeNode Dim virtualFolderPath As String ds = New DataSet() If parentNode Is Nothing Then virtualFolderPath = VirtualImageRoot ds = ClsFileapp.GetRootFolder() Else ds = ClsFileapp.GetRootFolder(val) virtualFolderPath = parentNode.Value & val & "/" End If Dim node As New TreeNode(ClsFileapp.GetfolderName(val), val) Dim reader As IDataReader = ds.CreateDataReader While reader.Read() Dim child As TreeNode = AddNodeAndDescendent(CInt(reader("id")), node) child.NavigateUrl = "FileApplication.aspx?id=" & reader("id") child.SelectAction = TreeNodeSelectAction.Expand node.ChildNodes.Add(child) End While Return node End Function Private Sub DisplayFileNFolder(ByVal folderid As String) ds = New DataSet() ds = ClsFileapp.GetFilesFolder(CInt(folderid)) If ds.Tables(0).Rows.Count > 0 Then DLDIsplayFiles.DataSource = ds DLDIsplayFiles.DataBind() End If End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load GetCurId = Request.QueryString.Get("id") If GetCurId IsNot Nothing Then DisplayFileNFolder(GetCurId) End If If Not IsPostBack Then PopulateTree() MPopupcreate.Hide() End If End Sub Protected Sub TvFile_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TvFile.SelectedNodeChanged TvFile.SelectedNodeStyle.BackColor = Drawing.Color.Blue End Sub End Class
-
hi, I have codebelow to populate treeview it works fine & binds value & text to nodes perfectly, I want to set background for selected nodes & get pathvalue of selected nodes I tried to put code inside TvFile_SelectedNodeChanged but it fires only for root node. it doenst fire for any other node.please help me to get selected node value please help me out, code Partial Class FileApplication Inherits System.Web.UI.Page Private Const VirtualImageRoot As String = "~/FileFolder/" Private ClsFileapp As New TreeFileApplication Private GetCurId As String = String.Empty Private ds As DataSet Private Sub PopulateTree() Dim rootFolder As New DirectoryInfo(Server.MapPath(VirtualImageRoot)) Dim root As TreeNode = AddNodeAndDescendent(0, Nothing) TvFile.Nodes.Add(root) End Sub Private Function AddNodeAndDescendent(ByVal val As Integer, ByVal parentNode As TreeNode) As TreeNode Dim virtualFolderPath As String ds = New DataSet() If parentNode Is Nothing Then virtualFolderPath = VirtualImageRoot ds = ClsFileapp.GetRootFolder() Else ds = ClsFileapp.GetRootFolder(val) virtualFolderPath = parentNode.Value & val & "/" End If Dim node As New TreeNode(ClsFileapp.GetfolderName(val), val) Dim reader As IDataReader = ds.CreateDataReader While reader.Read() Dim child As TreeNode = AddNodeAndDescendent(CInt(reader("id")), node) child.NavigateUrl = "FileApplication.aspx?id=" & reader("id") child.SelectAction = TreeNodeSelectAction.Expand node.ChildNodes.Add(child) End While Return node End Function Private Sub DisplayFileNFolder(ByVal folderid As String) ds = New DataSet() ds = ClsFileapp.GetFilesFolder(CInt(folderid)) If ds.Tables(0).Rows.Count > 0 Then DLDIsplayFiles.DataSource = ds DLDIsplayFiles.DataBind() End If End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load GetCurId = Request.QueryString.Get("id") If GetCurId IsNot Nothing Then DisplayFileNFolder(GetCurId) End If If Not IsPostBack Then PopulateTree() MPopupcreate.Hide() End If End Sub Protected Sub TvFile_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TvFile.SelectedNodeChanged TvFile.SelectedNodeStyle.BackColor = Drawing.Color.Blue End Sub End Class
-
hi, I have codebelow to populate treeview it works fine & binds value & text to nodes perfectly, I want to set background for selected nodes & get pathvalue of selected nodes I tried to put code inside TvFile_SelectedNodeChanged but it fires only for root node. it doenst fire for any other node.please help me to get selected node value please help me out, code Partial Class FileApplication Inherits System.Web.UI.Page Private Const VirtualImageRoot As String = "~/FileFolder/" Private ClsFileapp As New TreeFileApplication Private GetCurId As String = String.Empty Private ds As DataSet Private Sub PopulateTree() Dim rootFolder As New DirectoryInfo(Server.MapPath(VirtualImageRoot)) Dim root As TreeNode = AddNodeAndDescendent(0, Nothing) TvFile.Nodes.Add(root) End Sub Private Function AddNodeAndDescendent(ByVal val As Integer, ByVal parentNode As TreeNode) As TreeNode Dim virtualFolderPath As String ds = New DataSet() If parentNode Is Nothing Then virtualFolderPath = VirtualImageRoot ds = ClsFileapp.GetRootFolder() Else ds = ClsFileapp.GetRootFolder(val) virtualFolderPath = parentNode.Value & val & "/" End If Dim node As New TreeNode(ClsFileapp.GetfolderName(val), val) Dim reader As IDataReader = ds.CreateDataReader While reader.Read() Dim child As TreeNode = AddNodeAndDescendent(CInt(reader("id")), node) child.NavigateUrl = "FileApplication.aspx?id=" & reader("id") child.SelectAction = TreeNodeSelectAction.Expand node.ChildNodes.Add(child) End While Return node End Function Private Sub DisplayFileNFolder(ByVal folderid As String) ds = New DataSet() ds = ClsFileapp.GetFilesFolder(CInt(folderid)) If ds.Tables(0).Rows.Count > 0 Then DLDIsplayFiles.DataSource = ds DLDIsplayFiles.DataBind() End If End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load GetCurId = Request.QueryString.Get("id") If GetCurId IsNot Nothing Then DisplayFileNFolder(GetCurId) End If If Not IsPostBack Then PopulateTree() MPopupcreate.Hide() End If End Sub Protected Sub TvFile_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TvFile.SelectedNodeChanged TvFile.SelectedNodeStyle.BackColor = Drawing.Color.Blue End Sub End Class
Hi man, try with IValue convertor. Search google with that and also in code project itself you will find some great examples almost precisely the same as what you are looking for. Good luck. :)
Niladri Biswas