traversing through a treeview web control
-
i want to traverse through a treeview web control and fetch the ID's of all checked nodes. that is, all those nodes whose checkboxes are checked in a treeview.i want to get their Id's. i've used the following code : ''' For getting selected contact id's from the Group Tree Function GetContacts() As ArrayList Dim mnode As Microsoft.Web.UI.WebControls.TreeNode Dim contacts As New ArrayList Viewstate("ContactCounter") = 0 For Each mnode In TV_MasterContactList.Nodes GetSelectedContactID(mnode.GetNodeIndex, contacts) Next Return contacts End Function Sub GetSelectedContactID(ByVal Tnode As String, ByRef Contacts As ArrayList) Dim nnode As Microsoft.Web.UI.WebControls.TreeNode If TV_MasterContactList.GetNodeFromIndex(Tnode).Type = "Contact" And TV_MasterContactList.GetNodeFromIndex(Tnode).Checked = True Then Contacts.Add(TV_MasterContactList.GetNodeFromIndex(Tnode).ID) End If For Each nnode In TV_MasterContactList.GetNodeFromIndex(Tnode).Nodes GetSelectedContactID(nnode.GetNodeIndex(), Contacts) Next End Sub but its not giving the correct result regards, Kapil
-
i want to traverse through a treeview web control and fetch the ID's of all checked nodes. that is, all those nodes whose checkboxes are checked in a treeview.i want to get their Id's. i've used the following code : ''' For getting selected contact id's from the Group Tree Function GetContacts() As ArrayList Dim mnode As Microsoft.Web.UI.WebControls.TreeNode Dim contacts As New ArrayList Viewstate("ContactCounter") = 0 For Each mnode In TV_MasterContactList.Nodes GetSelectedContactID(mnode.GetNodeIndex, contacts) Next Return contacts End Function Sub GetSelectedContactID(ByVal Tnode As String, ByRef Contacts As ArrayList) Dim nnode As Microsoft.Web.UI.WebControls.TreeNode If TV_MasterContactList.GetNodeFromIndex(Tnode).Type = "Contact" And TV_MasterContactList.GetNodeFromIndex(Tnode).Checked = True Then Contacts.Add(TV_MasterContactList.GetNodeFromIndex(Tnode).ID) End If For Each nnode In TV_MasterContactList.GetNodeFromIndex(Tnode).Nodes GetSelectedContactID(nnode.GetNodeIndex(), Contacts) Next End Sub but its not giving the correct result regards, Kapil
-
i want to traverse through a treeview web control and fetch the ID's of all checked nodes. that is, all those nodes whose checkboxes are checked in a treeview.i want to get their Id's. i've used the following code : ''' For getting selected contact id's from the Group Tree Function GetContacts() As ArrayList Dim mnode As Microsoft.Web.UI.WebControls.TreeNode Dim contacts As New ArrayList Viewstate("ContactCounter") = 0 For Each mnode In TV_MasterContactList.Nodes GetSelectedContactID(mnode.GetNodeIndex, contacts) Next Return contacts End Function Sub GetSelectedContactID(ByVal Tnode As String, ByRef Contacts As ArrayList) Dim nnode As Microsoft.Web.UI.WebControls.TreeNode If TV_MasterContactList.GetNodeFromIndex(Tnode).Type = "Contact" And TV_MasterContactList.GetNodeFromIndex(Tnode).Checked = True Then Contacts.Add(TV_MasterContactList.GetNodeFromIndex(Tnode).ID) End If For Each nnode In TV_MasterContactList.GetNodeFromIndex(Tnode).Nodes GetSelectedContactID(nnode.GetNodeIndex(), Contacts) Next End Sub but its not giving the correct result regards, Kapil
when i check some checkboxes and on button click call these functions to retrieve the checked checkboxes Id. it shows even the checked checkboxes as unchecked and thus doesnt returns any Id's
-
when i check some checkboxes and on button click call these functions to retrieve the checked checkboxes Id. it shows even the checked checkboxes as unchecked and thus doesnt returns any Id's
You might want to debug your application and try to step through your sample code line by line. Also, i'm curious that why you don't just use the TreeNode instance from the Nodes collection instead of using the GetNodeFromIndex method. Anyway, below is a quick example for this:
private ArrayList GetContacts()
ArrayList Contacts = new ArrayList();foreach(TreeNode node in TV\_MasterContactList.Nodes) { GetSelectedContactID(node, Contacts); } return Contacts;
}
private void GetSelectedContactID(TreeNode node, ArrayList Contacts)
{
if(node.Checked)
Contacts.Add(node.ID);foreach(TreeNode child in node.Nodes) { GetSelectedContactID(child, Contacts); }
}