.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 31st, 2008, 09:48 AM
Jenny911 Jenny911 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 35 Jenny911 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 33 m 31 sec
Reputation Power: 1
Example code for treeview control populated from DB2 tables

Hey all! I am new to Visual Studio 2005 and was wondering if anyone had some example code on how to populate a treeview control based on values in DB2 tables? Thanks in advance!

Reply With Quote
  #2  
Old January 31st, 2008, 09:56 AM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
Click here for more information.
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,384 lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 23 h 40 m 30 sec
Reputation Power: 1488
Please don't crosspost.

I've deleted your other thread with the same topic.

I found this that can help you out with your problem.
If you get stuck implementing it, please post here on this same thread.
__________________
................... ASCII and ye shall receive ..................
Knowledge is the only resource on earth that multiplies when shared


Support the Shemzilla Project
Powered by C#

Reply With Quote
  #3  
Old February 1st, 2008, 08:43 AM
Jenny911 Jenny911 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 35 Jenny911 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 33 m 31 sec
Reputation Power: 1
Errors in

Imports System.Data
Imports System.Data.SQLClient
Using System.Web.UI.WebControls

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim strConn As String = "server=***********;database=*****;UID=****;passwor d=********;"
Dim objConn As New SqlConnection(strConn)
Dim objDS As DataSet
Dim daClass As New SqlDataAdapter("SELECT *", objConn)
Dim daCateg As New SqlDataAdapter("SELECT *", objConn)

daClass.Fill(objDS, "dtClass")
daCateg.Fill(objDS, "dtCateg")
objConn.Close()
objDS.Tables("*").Columns("*")
objDS.Tables("*").Columns("*")


Dim nodeClass, nodeCateg As TreeNode
Dim rowClass, rowCateg As DataRow

For Each rowClass In objDS.Tables("dtClass").Rows
nodeClass = New TreeNode
nodeClass.Text = rowClass("*")
nodeClass.Text = rowClass("*")
TreeView1.Nodes.Add(nodeClass)

For Each rowCateg In rowClass.GetChildRows("ClassToCateg")
nodeCateg = New TreeNode
nodeCateg.Text = rowCateg("*")
nodeCateg.Text = rowCateg("*")
TreeView1.Nodes.Add(nodeCateg)
Next
Next

'Clean up
objDS.Dispose()
daClass.Dispose()
daCateg.Dispose()
objConn.Close()
objConn.Dispose()
End Sub
End Class

Whenever I build my file, I get the following errors:
Using System.Web.UI.WebControls - "Statement cannot appear outside a method body"

objDS.Tables("*").Columns("*")
objDS.Tables("*").Columns("*") - "Property access must assign to the property or use its value"

I am trying to create a treeview control that is populated by values in DB2 tables. Please advise! Thanks in advance!

Reply With Quote
  #4  
Old February 1st, 2008, 08:44 AM
Jenny911 Jenny911 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 35 Jenny911 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 33 m 31 sec
Reputation Power: 1
Just as an FYI - I was getting the same error on Using Microsoft.Web.UI.WebControls that I am for System.Web.UI.WebControls. Thanks!

Reply With Quote
  #5  
Old February 1st, 2008, 08:52 AM
jmurrayhead jmurrayhead is offline
Moderator
ASP Free God 17th Plane (13000 - 13499 posts)
 
Join Date: Feb 2004
Location: Reston, VA, USA
Posts: 13,091 jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)  Folding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced Folder
Time spent in forums: 3 Months 1 Week 10 h 7 m 2 sec
Reputation Power: 1580
Change this:
Code:
Using System.Web.UI.WebControls


to this:
Code:
Imports System.Web.UI.WebControls


What are you trying to do with this bit:
Code:
objDS.Tables("DATA_CLASS").Columns("DATA_CLASS_ID")
objDS.Tables("DATA_CATEG").Columns("DATA_CLASS_ID")


As the error states, you must either get the value or set the value of this property.
__________________
jmurrayhead

Did I help you out? Make me popular by clicking the icon!

New Members:Proper way to post a question

Powered by ASP.Net

Reply With Quote
  #6  
Old February 1st, 2008, 08:58 AM
Jenny911 Jenny911 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 35 Jenny911 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 33 m 31 sec
Reputation Power: 1
I am trying to creating a relation between the parent table and the child table with those two lines. This is the first time that I have used a treeview control and I am not sure exactly on the syntax of those two lines. Please advise! Thanks!

Reply With Quote
  #7  
Old February 7th, 2008, 11:26 AM
Jenny911 Jenny911 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 35 Jenny911 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 33 m 31 sec
Reputation Power: 1
Quote:
Originally Posted by Jenny911
I am trying to creating a relation between the parent table and the child table with those two lines. This is the first time that I have used a treeview control and I am not sure exactly on the syntax of those two lines. Please advise! Thanks!



Dim strConn As String = "Provider=IBMDADB2.1;Password=********;User ID=********;Data Source=EBWEB;Persist Security Info=True;"
Dim objConn As New OleDbConnection(strConn)
objConn.Open()

Dim daClass As String = "SELECT DATA_CLASS_NM, DATA_CLASS_ID FROM NDDBA.DATA_CLASS"
Dim da1 As OleDbDataAdapter = New OleDbDataAdapter(daClass, objConn)
Dim ds1 As DataSet = New DataSet("DATA_CLASS")

Dim daCateg As String = "SELECT DATA_CATEG_NM, DATA_CLASS_ID FROM NDDBA.DATA_CATEG"
Dim da2 As OleDbDataAdapter = New OleDbDataAdapter(daCateg, objConn)
'Dim ds2 As DataSet = New DataSet("DATA_CATEG")

da1.Fill(ds1, "DATA_CLASS")
da2.Fill(ds1, "DATA_CATEG")

objConn.Close()

ds1.Relations.Add("ClassToCateg", _
ds1.Tables("DATA_CLASS").Columns("DATA_CLASS_ID"), _
ds1.Tables("DATA_CATEG").Columns("DATA_CLASS_ID"))

Dim nodeClass, nodeCateg As TreeNode
Dim rowClass, rowCateg As DataRow


For Each rowClass In ds1.Tables("DATA_CLASS").Rows
nodeClass = New TreeNode
nodeClass.Text = rowClass("DATA_CLASS_NM")
nodeClass.Value = rowClass("DATA_CLASS_ID")
TreeView1.Nodes.Add(nodeClass)
Next

This is the code I have so far. I am not getting an error. It shows all of the DATA_CLASS_NM's that are in the table. Whenever I select one of them, it just reprints all of the DATA_CLASS_NM's. I need it to where when I click on one of the DATA_CLASS_NM's, the DATA_CATEG_NM's that are associated with the DATA_CLASS_NM selected appears as child nodes under it in the treeview control. Thanks in advance!

Reply With Quote
  #8  
Old February 8th, 2008, 10:39 AM
jmurrayhead jmurrayhead is offline
Moderator
ASP Free God 17th Plane (13000 - 13499 posts)
 
Join Date: Feb 2004
Location: Reston, VA, USA
Posts: 13,091 jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)  Folding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced Folder
Time spent in forums: 3 Months 1 Week 10 h 7 m 2 sec
Reputation Power: 1580
Have a look at my thread here: Dynamic TreeView

I modified the code for use with a TreeView and it is attached to the post as treeview_vb.zip.

See if you can modify that sample to do as you need. Take into consideration the database setup in the post.
Comments on this post
AOG123 agrees: Nice and Smooth

Last edited by jmurrayhead : April 2nd, 2008 at 09:29 AM. Reason: error

Reply With Quote
  #9  
Old February 11th, 2008, 10:27 AM
Jenny911 Jenny911 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 35 Jenny911 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 33 m 31 sec
Reputation Power: 1
Quote:
Originally Posted by jmurrayhead
Have a look at my thread here: Dynamic Treeview

I modified the code for use with a TreeView and it is attached to the post as Default1.txt.

See if you can modify that sample to do as you need. Take into consideration the database setup in the post.


Hey jmurrayhead! Thanks for the code! I have modified my code and whenever I run the program I get the following error: 'System.Web.UI.WebControls.TreeView' does not allow child controls.'

Could you tell me what this means? Thanks in advance!

Last edited by jmurrayhead : April 2nd, 2008 at 09:35 AM.

Reply With Quote
  #10  
Old February 11th, 2008, 10:31 AM
jmurrayhead jmurrayhead is offline
Moderator
ASP Free God 17th Plane (13000 - 13499 posts)
 
Join Date: Feb 2004
Location: Reston, VA, USA
Posts: 13,091 jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)  Folding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced Folder
Time spent in forums: 3 Months 1 Week 10 h 7 m 2 sec
Reputation Power: 1580
What line causes this error? Post that code here

Reply With Quote
  #11  
Old February 11th, 2008, 10:47 AM
Jenny911 Jenny911 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 35 Jenny911 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 33 m 31 sec
Reputation Power: 1
Quote:
Originally Posted by jmurrayhead
What line causes this error? Post that code here


It looks like the error is being generated here in the PopulateTreeView()

Me.TreeView1.Controls.Add(TreeView)

Thanks!

Reply With Quote
  #12  
Old February 11th, 2008, 10:51 AM
jmurrayhead jmurrayhead is offline
Moderator
ASP Free God 17th Plane (13000 - 13499 posts)
 
Join Date: Feb 2004
Location: Reston, VA, USA
Posts: 13,091 jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)  Folding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced FolderFolding Points: 87252 Folding Title: Advanced Folder
Time spent in forums: 3 Months 1 Week 10 h 7 m 2 sec
Reputation Power: 1580
Look more closely at my code sample. It should be:

Code:
Me.pnlTreeView.Controls.Add(TreeView)

Where pnlTreeView is the asp:Panel control. This line is adding the programmatically created TreeView to the panel controls collection.

Reply With Quote
  #13  
Old February 11th, 2008, 01:42 PM
Jenny911 Jenny911 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 35 Jenny911 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 33 m 31 sec
Reputation Power: 1
Quote:
Originally Posted by jmurrayhead
Look more closely at my code sample. It should be:

Code:
Me.pnlTreeView.Controls.Add(TreeView)

Where pnlTreeView is the asp:Panel control. This line is adding the programmatically created TreeView to the panel controls collection.


Ugh! I cannot seem to get this to work! I am not getting any errors but nothing at all is being displayed. I think I am confused on where to put my field names. Also, I have to pull values out of more than one DB2 table. Would I not have to set up a new datatable to account for that? itemid, parentid, linetext, lineurl are all confusing. I am not sure where my field names need to be plugged in! My field names are DATA_CLASS_NM, DATA_CATEG_NM, DATA_CLASS_ID, DATA_CATEG_ID. The DATA_CLASS_ID is in both tables and that is how I know what DATA_CATEG_NM's are associated with what DATA_CLASS_NM's. I am new to ASP.NET, Visual Studio 2005, and the TreeView Control. I am trying to debug my program but I am having trouble with it because I am not used to the debugger! Please help!!! Thanks!

Reply With Quote