Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

HierarchicalDataSourceControl problem

[es] :: .NET :: HierarchicalDataSourceControl problem

[ Pregleda: 1584 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

nristic
Hrvatska

Član broj: 11531
Poruke: 55
*.adsl.net.t-com.hr.

Sajt: www.titlovi.net


Profil

icon HierarchicalDataSourceControl problem11.04.2006. u 13:41 - pre 219 meseci
Imam jednu kolekciju objekata koju zelim prikazati u kontrol treeview.
Kreirao sam svoju kontrolu datasource prema primjeru koji se nalazi u
.NET Framework dokumentaciji (FileSystemDataSource).

Problem je sljedeci

1.Kada pokusam pokrenuti primjer dobivam exception tipa stackoverflow.
No recimo ako zadani folder nema podfoldera stvar radi kako spada.

2.Ista stvar je i sa kontrolom koju sam kreirao.

Ako ne koristim datasource kontrolu vec bindam direktno na treeview kontrolu

Code:

    Dim dsv  As HierarchicalDataSourceView = new HierarchicalDataSourceView("")

        tree.datasource = dsv.select
        tree.DataBind()


Onda stvar donekle radi kako spada. Tj ne radi jer za svaki objekt prikazuje njegove child objekte bez obzira da
li su vec prikazani ili ne.Recimo ako ima 10 podataka kojih treba prikazati kontrola ce prikazati 10 ili vise zapisa
ovisno o tome da li neki objekt ima child objekt.

Ako ima netko da isproba primjer koji se nalazi u dokumentaciji pa da mi kaze da li dobiva isti klinac kao ja.
Vise ni sam ne znam sta da isprobam. Probao sam sve metode u klasama testirati i sve rade kako spadaju.


Code:

    Public Class CategoryDataSource : Inherits HierarchicalDataSourceControl

        Private _view As CategoryDataSourceView = Nothing

        Protected Overrides Function GetHierarchicalView(ByVal viewPath As String) As System.Web.UI.HierarchicalDataSourceView
            If _view Is Nothing Then
                _view = New CategoryDataSourceView(viewPath)
            End If

            Return _view
        End Function

    End Class

    Public Class CategoryDataSourceView : Inherits HierarchicalDataSourceView

        Public Sub New(ByVal viewpath As String)
        End Sub

        Public Overrides Function [Select]() As System.Web.UI.IHierarchicalEnumerable
            Dim ce As CategoryEnumerable = New CategoryEnumerable
            Dim _cc As CategoryCollection = ShopManager.GetAllCategories()

            If _cc.Count > 0 Then
                For Each c As Category In _cc
                    ce.Add(New CategoryData(c))
                Next
            End If

            Return ce
        End Function

    End Class

    Public Class CategoryData : Implements IHierarchyData, INavigateUIData

        Private _c As Category = Nothing
        Private _cc As CategoryCollection = Nothing

        Public Sub New(ByVal c As Category)
            _c = c
            _cc = ShopManager.GetAllCategories
        End Sub

        Public Function GetChildren() As System.Web.UI.IHierarchicalEnumerable Implements System.Web.UI.IHierarchyData.GetChildren
            Dim ce As CategoryEnumerable = New CategoryEnumerable
            RecursiveAdd(ce, _c)

            Return ce
        End Function

        Private Sub RecursiveAdd(ByRef ce As CategoryEnumerable, ByVal c As Category)
            For i As Integer = 0 To _cc.Count - 1
                Dim _c As Category = _cc(i)

                If c.Categoryid = _c.ParentCategoryid And _c.Categoryid <> c.Categoryid Then
                    ' RecursiveAdd(ce, _c)

                    ce.Add(New CategoryData(_c))
                End If
            Next
        End Sub

        Public Function GetParent() As System.Web.UI.IHierarchyData Implements System.Web.UI.IHierarchyData.GetParent
            Dim cd As CategoryData = Nothing

            If _c.ParentCategoryid <> 0 Then
                For i As Integer = 0 To _cc.Count - 1
                    Dim c As Category = _cc(i)

                    If _c.ParentCategoryid = c.Categoryid Then
                        cd = New CategoryData(c)
                    End If
                Next
            End If

            Return cd
        End Function

        Public ReadOnly Property HasChildren() As Boolean Implements System.Web.UI.IHierarchyData.HasChildren
            Get
                Dim has As Boolean = False

                For i As Integer = 0 To _cc.Count - 1
                    Dim c As Category = _cc(i)

                    If _c.Categoryid = c.ParentCategoryid Then
                        has = True
                    End If
                Next

                Return has '_c.HasChild
            End Get
        End Property

        Public ReadOnly Property Item() As Object Implements System.Web.UI.IHierarchyData.Item
            Get
                Return _c
            End Get
        End Property

        Public ReadOnly Property Path() As String Implements System.Web.UI.IHierarchyData.Path
            Get
                Return _c.Description
            End Get
        End Property

        Public ReadOnly Property Type() As String Implements System.Web.UI.IHierarchyData.Type
            Get
                Return "CategoryData"
            End Get
        End Property

        Public ReadOnly Property Description() As String Implements System.Web.UI.INavigateUIData.Description
            Get
                Return _c.Name
            End Get
        End Property

        Public ReadOnly Property Name() As String Implements System.Web.UI.INavigateUIData.Name
            Get
                Return _c.Name
            End Get
        End Property

        Public ReadOnly Property NavigateUrl() As String Implements System.Web.UI.INavigateUIData.NavigateUrl
            Get
                Return "Default.aspx?categoryid="
            End Get
        End Property

        Public ReadOnly Property Value() As String Implements System.Web.UI.INavigateUIData.Value
            Get
                Return _c.Name
            End Get
        End Property

    End Class

    Public Class CategoryEnumerable : Inherits ArrayList
        Implements IHierarchicalEnumerable

        Public Function GetHierarchyData(ByVal enumeratedItem As Object) As System.Web.UI.IHierarchyData Implements System.Web.UI.IHierarchicalEnumerable.GetHierarchyData
            Return CType(enumeratedItem, IHierarchyData)
        End Function

    End Class

 
Odgovor na temu

[es] :: .NET :: HierarchicalDataSourceControl problem

[ Pregleda: 1584 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.