PDA

View Full Version : [CLOSED] TreeStore with IHierarchicalDataSource



bbros
Oct 24, 2013, 11:04 AM
Hi,
I'm trying to bind a TreePanel's Store with a IHierarchicalDataSource with this (VB.NET) code:



sender.Store(0).DataSource = New AttivitaHDataSource(GetDTAttivita(AddressOf adapter.Attivita.Fill))
sender.Store(0).DataBind()


AttivitaHDataSource is a hierarchical data source built from a datatable. The constructor's argument is the datatable.
This approach works just fine with an ASP.NET TreeView, but with the TreeStore I get a NullReferenceException at the .DataBind() step.

Is this supported? I haven't found much documentation. Can you provide an example?

Motivation: I follow this approach to refresh the content of a GridPanel with server-side code and I'd rather do the same with the TreePanel than reload with client-side code.

Thanks!

Daniil
Oct 24, 2013, 1:41 PM
Hi @bbros,

Binding an IHierarchicalDataSource to a TreeStore is supported.

Here is an example.
http://examples2.ext.net/#/TreePanel/Loaders/Xml_File_Loading/

So, you should probably configure a TreeStore's DataBindings.

bbros
Oct 24, 2013, 3:24 PM
So, you should probably configure a TreeStore's DataBindings.

Thanks, but that didn't work; I still get the null reference exception.
I switched to client-side refreshing, following this example:

http://examples2.ext.net/#/TreePanel/Basic/Refresh_Static_Tree/

It works fine.

Daniil
Oct 24, 2013, 3:32 PM
Thanks, but that didn't work; I still get the null reference exception.

If you can provide a test case, we would be glad to investigate.




I switched to client-side refreshing, following this example:

http://examples2.ext.net/#/TreePanel/Basic/Refresh_Static_Tree/

It works fine.

Nice!

bbros
Oct 24, 2013, 4:47 PM
If you can provide a test case, we would be glad to investigate.


With pleasure. I put together a sample project and uploaded it here (the forum won't let me attach zip files):

http://ge.tt/api/1/files/6Cily9w/0/blob?download

In this project:

the page TreeView.aspx contains an ASP.NET TreeView control that works
the Default.aspx page contains a TreePanel that causes the null reference exception with the same hierarchical datasource

Daniil
Oct 25, 2013, 6:59 AM
Thank you. We are investigating.

P.S. It is better to post the code samples directly here wrapping in code tags. Sure, it should be simplified/minified before.

Vladimir
Oct 25, 2013, 4:39 PM
Can you post TreeView.aspx with DataBindings (to read Attivita field as text)?

bbros
Oct 26, 2013, 8:42 AM
Can you post TreeView.aspx with DataBindings (to read Attivita field as text)?

I'm not sure I understand, sorry.

The datatable is defined in the Common.vb file as follows:



Dim dt = New DataSet1.AttivitaDataTable

With dt
Dim row1 = .NewAttivitaRow
row1.idAttivita = 1
row1.Attivita = "a"
.AddAttivitaRow(row1)

Dim row2 = .NewAttivitaRow
row2.idAttivita = 2
row2.Attivita = "b"
.AddAttivitaRow(row2)

Dim row3 = .NewAttivitaRow
row3.idAttivita = 3
row3.idAttivitaParent = 1
row3.Attivita = "c"
.AddAttivitaRow(row3)
End With

and this is what the TreeView shows:

7121

So the TreeView is already showing the Attivita field as text: "a", "b" and "c" are the Attivita fields in the three records (I could have chosen better examples, sure).

Did you mean something else?

P.S. The databinding for the TreeView is in the code behind:



Public Class TreeView
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TreeView1.DataSource = Common.GetHDS
TreeView1.DataBind()
End Sub

End Class

Common.GetHDS returns a hierarchical data source (implementing the IHierarchicalDataSource interface) built from the datatable defined above.

Vladimir
Oct 26, 2013, 9:25 AM
Your TreeView sample has no any defined DataBindings, it means that TreeView will use ToString method for items (without reading any additinal fields)

If you update from SVN then Ext.Net can work with your data without defined DataBindings (like in TreeView sample)


Imports Ext.Net


Public Class _Default
Inherits System.Web.UI.Page


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim s = New TreeStore With {.ID = "AttivitaTreeStore"}
Dim tp = New TreePanel With {.ID = "TP"}
tp.Store.Add(s)
Me.Controls.Add(tp)


tp.GetStore.DataSource = Common.GetHDS
tp.DataBind()


End Sub


End Class


If you need any additional fields then you have to define DataBindings. I am not sure what exactly DataMember should be defined in DataBinding therefore I asked about ASP.NET sample with TreeView where DataBindings is used