Ralph Varjabedian
Coding is a systematic art

Binding ASP.NET TreeView to a DataSet or an ObjectDataSource using VB.NET

Thursday, May 29, 2008 4:32 PM

Thank you goes for Adrien Cuisinier who has ported the C# code of this topic to VB.NET. Now you can download the sample application in VB.NET. You can contact Adrien here if you want to.


Feedback

# re: Binding ASP.NET TreeView to a DataSet or an ObjectDataSource using VB.NET

A slight bug in the translation. In the two constructors the last couple of lines need replacing with:

Me.columnIsString = (dataView.Table.Columns(idColumnName).DataType Is GetType(String))

The original code was trying to set the column type, then always setting columnIsString to True. 9/9/2008 12:09 PM | Richard

# re: Binding ASP.NET TreeView to a DataSet or an ObjectDataSource using VB.NET

Thank you Richard for your feedback. The translation was made by a fellow developer since I am that familiar with VB.NET syntax. I will make sure to correct the translation. Thanks. 9/11/2008 11:44 AM | Ralph Varjabedian

# re: Binding ASP.NET TreeView to a DataSet or an ObjectDataSource using VB.NET

I'm using the code to test the use of a treeview for displaying Oracle data. The treeview is added to a new web form. The IHierarchicalDataSource code is added to the project and "imported" into the code behind. In the page_load, I create a dataset from a stored procedure. The dataset is returned and contains the proper data. I use the following line to set the data source:

treeviewer.datasource - new hierarchicalDataSet(ds, "Milestone_ID", "Parent_key")

The code runs through the constructor and properly identifies the columns and their types BUT -- when the control is returned to the line above, I get a "nullReferenceException error".

I can get no further. Since I know the object and the dataset are both present, do you have any idea what is coming back "null" and what I need to do to fix it?

Respectfully, 9/11/2008 11:13 PM | Vicki Combs

# re: Binding ASP.NET TreeView to a DataSet or an ObjectDataSource using VB.NET

If you can send me the data, I would gladly debug it for you, the easiest way is to load it into a dataset and use ExportToXML to send me an xml file with the data.

Regards. 9/12/2008 12:14 PM | Ralph Varjabedian

# re: Binding ASP.NET TreeView to a DataSet or an ObjectDataSource using VB.NET

Wow! Thanks for the prompt reply. I don't mean to be stupid, Ralph, but I don't know how to attach a file to this form nor do I have your email address. So how do I send you the xml file with the data?

9/12/2008 5:10 PM | Vicki Combs

# re: Binding ASP.NET TreeView to a DataSet or an ObjectDataSource using VB.NET

Unlike ASP, in ASP.NET, directives can appear anywhere on a page, but are most commonly written as the very first lines.ASP.NET pages are simply text files with the .aspx file name extension that can be placed on an IIS server equipped with ASP.NET.
12/10/2009 12:35 PM | online Chinese casinos

# re: Binding ASP.NET TreeView to a DataSet or an ObjectDataSource using VB.NET

I'm using the code to test the use of a treeview for displaying Oracle data. The treeview is added to a new web form. The IHierarchicalDataSource code is added to the project and "imported" into the code behind. 12/22/2009 9:29 PM | Web Hosting

# re: Binding ASP.NET TreeView to a DataSet or an ObjectDataSource using VB.NET

I just wanted to add my thanks for your excellent code. This has been a real timesaver and a much more elegant solution that I was able to create. Many thanks again. 1/26/2010 8:34 PM | Samuel Moise

# re: Binding ASP.NET TreeView to a DataSet or an ObjectDataSource using VB.NET

From one Ralph to another, thank you, thank you, THANK YOU. I hvae been looking for one approach to deal with both the treeview control and the menu control out of a database. With only a little tweeking, I was able to use your code and integrate it into the website currently under development. 1/31/2010 7:51 PM | Ralph Outcalt

# re: Binding ASP.NET TreeView to a DataSet or an ObjectDataSource using VB.NET

You are welcome Ralph :) I am glad my code helps fellow developers. 2/11/2010 11:53 PM | Ralph Varjabedian

# re: Binding ASP.NET TreeView to a DataSet or an ObjectDataSource using VB.NET

Hi,
First Thanks a lot for your effort, and the code is clearly quite a hard work. I am sort of an amateur programmer and i need your help at passing my get the data from MSSQL 2008,

In the aspx.vb page i replaced the code with the code below to pass the data: (please note user id and password for connectionstring are replaced by XXXX, my connection to sql is working )



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

Dim objConn As New SqlConnection("Data Source=tcp:XXXXX.discountasp.net;Initial Catalog=SQL2008_698393_tgc;User ID=XXXX;Password=XXXX;")
Dim objCommand As New SqlCommand("select ID,ParentID,Text FROM CatalogueWeb", objConn)
Dim da As New SqlDataAdapter(objCommand)
Dim dataTable As New DataTable()
Dim dataSet As New DataSet()
dataSet.Tables.Add(dataTable)



' You can use this:
TreeView1.DataSource = New HierarchicalDataSet(dataSet, "ID", "ParentID")
' Or you can use the extensions for TreeView if you are using .NET 3.5
'TreeView1.SetDataSourceFromDataSet(dataSet, "ID", "ParentID");
TreeView1.DataBind()
End Sub


My table is exactly formed as needed but , i'm getting
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 52: Me.parentIdColumnName = parentIdColumnName
Line 53:
Line 54: If Not (dataSet.Tables(0).Columns(idColumnName).DataType Is dataSet.Tables(0).Columns(parentIdColumnName).DataType) Then
Line 55: Throw New Exception("The two column names passed should be of the same type")
Line 56: End If

error,

Could you give me your valuable insights on this?

Thnxx





2/13/2010 6:26 PM | Vedat Galimidi

Post a comment





 

Please add 4 and 7 and type the answer here: