ASP TreeView Control

  • Thread starter Thread starter Srinivasa Raghavan
  • Start date Start date
S

Srinivasa Raghavan

Hi

I am using ASP Tree View Control to display data in
hiearchy fashion.I am having a checkbox next to the
TreeView Node.When user checks or unchecks the nodes and
click a button i am putting that count in a
stringcollection which is in viewstate.The count is wrong
after certain checks and click of the button.can any one
explain what could be wrong.

Here is the code below.
nodeschecked count is going wrong what could be reason.

Private Sub Page_Load(ByVal sender As System.Object, ByVal
e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
nodesChecked = New StringCollection()
ViewState("Selected") = nodesChecked
Else
nodesChecked = CType(ViewState("Selected"),
StringCollection)
End If
End Sub

Private Sub TreeView1_Check(ByVal sender As Object, ByVal
e As
Microsoft.Web.UI.WebControls.TreeViewClickEventArgs)
Handles TreeView1.Check
Dim treeView As TreeView
Dim node As TreeNode
Dim strNodeChecked As String

treeView = CType(sender, TreeView)
strNodeChecked = e.Node
node = treeView.GetNodeFromIndex(strNodeChecked)

' the node will have been checked or unchecked
If node.Checked = True Then
nodesChecked.Add(node.Text)
Else
nodesChecked.Remove(node.Text)
End If


End Sub
End Class


Thanks
Srinivasa Raghavan
 
Srinivasa,

Your code looks fine except for one small thing: In your Sub
TreeView1_Check I don't see where you are saving the new nodesChecked object
to view state. If you don't re-save it to the view state variable every page
load the view state is re-setting it to the empty value.

Change your code to look like this and it will work I think:

' the node will have been checked or unchecked
If node.Checked = True Then
nodesChecked.Add(node.Text)
Else
nodesChecked.Remove(node.Text)
End If

ViewState("Selected") = nodesChecked


Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
Hi


I am storing cookies in the client side using httpcookie object.It is
working in IE and not in netscape.please suggest a solution.


I am having javascript which works in IE and not in Netscape.Basically
when clicking checkbox in grid i call the javascript.In Netscape the i
am unable to deselected the checkbox once selected.



Thanks
Srinivasa Raghavan
 
Back
Top