ASP TreeView Control

  • Thread starter Srinivasa Raghavan
  • 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
 
S

S. Justin Gengo

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
 
S

Srinivasa Raghavan Sethuraman

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top