|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#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!
|
|
#2
|
||||
|
||||
|
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# |
|
#3
|
|||
|
|||
|
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! |
|
#4
|
|||
|
|||
|
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!
|
|
#5
|
|||
|
|||
|
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 .Net Help |
|
#6
|
|||
|
|||
|
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!
|
|
#7
|
|||
|
|||
|
Quote:
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! |
|
#8
|
|||
|
|||
|
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. Last edited by jmurrayhead : April 2nd, 2008 at 08:29 AM. Reason: error |
|
#9
|
|||
|
|||
|
Quote:
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 08:35 AM. |
|
#10
|
|||
|
|||
|
What line causes this error? Post that code here
|
|
#11
|
|||
|
|||
|
Quote:
It looks like the error is being generated here in the PopulateTreeView() Me.TreeView1.Controls.Add(TreeView) Thanks! |
|
#12
|
|||
|
|||
|
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. |
|
#13
|
|||
|
|||
|
Quote:
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! |
|
#14
|
|||
|
|||
|
Do the tables have the same schema (same fields and field types)? If so, then why use two separate tables? For my sample to work, you would have to have to relate the child menu items to their parent menu items. Items that have no parent item would have a parentid of 0.
Post a copy of both your table setups and I'll see what I can come up with. It might be possible to just use a join query to pull the relevant data, however it depends on your table setup. |
|
#15
|
|||
|
|||
|
Quote:
All of the NM fields are defined as VARCHAR and all of the ID fields are defined as INTEGER. Here is a listing of the tables: DATA_CLASS table: DATA_CLASS_ID DATA_CLASS_NM SBJCT_AREA_CATEG table: SBJCT_AREA_CATEG_ID SBJCT_AREA_CATEG_NM DATA_CLASS_ID SBJCT_AREA table: SBJCT_AREA_ID SBJCT_AREA_NM SBJCT_AREA_CATEG_ID ENT table: ENT_SURGT_ID ENT_NM SBJCT_AREA_ID ENT_ATRBT_RLSHP table: ENT_SURGT_ID ATRBT_SURGT_ID ATRBT table: ATRBT_SURGT_ID ATRBT_NM Just curious, is there a limit on how many child nodes a parent node can have? Really, I have more child nodes that I need to show in my treeview control. This is the order for my treeview control: + DATA_CLASS_NM's + SBJCT_AREA_CATEG_NM's + SBJCT_AREA_NM's + ENT_NM's + ATRBT_NM's I do not want to show a web form with general information until either an entity name or an attribute name is selected from the treeview control. I went ahead and listed all of the tables that I am going to have to deal with in order to get this treeview control working! Please let me know if you need more information from me. Thanks so much!! |
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > Example code for treeview control populated from DB2 tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|