嵌套的Datalists降至GreatGrandChild级别

时间:2013-07-16 20:16:03

标签: parent-child grandchild nested-datalist

我已经“成功”让嵌套数据专家工作了四代(Parent,Child,GrandChild,GreatGrandChild),但只有少于50的记录集和几乎一分钟的流失时间。现在我有大约500条记录,请求超时。

我已经尝试了几种我在网上找到成功获得Parent-Child数据列表的方法,但我无法通过GrandChild进行递归,而没有使用太多Open Connections的错误。

有没有人可以分享一个快速的四代嵌套数据主义者的最佳实践?

以下是数据绑定Child和GrandChild数据列表的示例代码:

Sub Item_Bound_Child(sender As Object, e As DataListItemEventArgs)

    If e.Item.ItemType = ListItemType.Item Or _
        e.Item.ItemType = ListItemType.AlternatingItem Then

        ' Retrieve the Label control in the current DataListItem.
        Dim Parent_Name_Label As Label = _
            CType(e.Item.FindControl("lbl_Parent_Name"), Label)

        Dim s As SqlDataSource = DirectCast(e.Item.FindControl("DataSource_Child_Data"), SqlDataSource)

        s.FilterParameters(0).DefaultValue = Parent_Name_Label.Text
        s.DataBind()


    End If

End Sub
Sub Item_Bound_GrandChild(sender As Object, e As DataListItemEventArgs)

    If e.Item.ItemType = ListItemType.Item Or _
        e.Item.ItemType = ListItemType.AlternatingItem Then

        ' Retrieve the Label control in the current DataListItem.
        Dim Parent_Name_Child_Level_Label As Label = _
            CType(e.Item.FindControl("lbl_Parent_Name_Child_Level"), Label)
        Dim Child_Name_Label As Label = _
            CType(e.Item.FindControl("lbl_Child_Name"), Label)

        Dim s As SqlDataSource = DirectCast(e.Item.FindControl("DataSource_GrandChild_Data"), SqlDataSource)

        s.FilterParameters(0).DefaultValue = Parent_Name_Child_Level_Label .Text
        s.FilterParameters(1).DefaultValue = Child_Name_Label .Text
        s.DataBind()

    End If

End Sub

我只能想象我在某处泄漏某些东西或者往返太多。我当然希望得到一些指导和帮助。

谢谢, 罗布

1 个答案:

答案 0 :(得分:0)

我发现这个解释对于为多级嵌套数据列表设置数据绑定非常有帮助。虽然代码最初非常令人生畏,但我学会了它并将其改编为我的使用。

http://msdn.microsoft.com/en-us/library/aa478959.aspx

现在我的嵌套数据列表会在几秒钟内显示出来。

我的下一步是学习如何编辑GreatGrandChild数据列表。