ASP.net:超过 2 个嵌套中继器

发布于 2024-09-16 16:19:46 字数 320 浏览 6 评论 0原文

我的数据来自数据库。我有一个包含一些基本属性的项目数据表。

Item 
{ 
   ID, 
   Name, 
   Description, 
   ... 
} 

然后我有一个多对多关系表:

Parent 
{ 
   ParentID, 
   ChildID 
} 

我正在迭代每个项目并显示其子项;我认为这最好通过嵌套重复器来完成,但我可能是错的。

如何使用 asp:repeaters 获得多个层次结构级别?我只用过一个嵌套中继器,我不知道如何做 3 个以上。

My data comes from a database. I have an item data table with some basic properties.

Item 
{ 
   ID, 
   Name, 
   Description, 
   ... 
} 

Then I have a many to many relationship table with:

Parent 
{ 
   ParentID, 
   ChildID 
} 

I'm iterating through each item and displaying its children; and its children's children, etc. I assume this would best be accomplished with nested repeaters, but I could be wrong.

How do I get multiple heirarchical levels using asp:repeaters? I've only ever used one nested repeater, I have no idea how to do 3+.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

開玄 2024-09-23 16:19:46

就我个人而言,我可能通过创建一个具有 Item 属性和某种 ParentsChildren 属性的自定义控件来实现此目的。该控件将显示 Item 上的详细信息,然后使用重复器显示 Parents / Children 中的每个元素,其中对于每个项目,重复器递归地显示使用相同的控件来呈现项目。

Personally I probably do this by creating a custom control with an Item property and some sort of either Parents or Children property. The control would display details on Item, and then use a repeater to show each element in Parents / Children, where for each item the repeater recursively uses the same control to render the item.

我早已燃尽 2024-09-23 16:19:46

我会按照@Kragen 说的去做。但如果您确实认为创建两个组件太多,您应该在数据绑定中使用一个中继器和两个 foreach 循环。
使用两个中继器在另一个内部是过于复杂的,更不用说 3 个中继器了:)。

I would do what @Kragen said. But if you really think that creating two components is too much you should use one repeater and two foreach loops in on data bound.
Using two repeaters one inside of another is overcomplicated not to mention 3 repeaters :).

灰色世界里的红玫瑰 2024-09-23 16:19:46

父子关系,是多对多吗?这没有道理,至少称他们为父母和孩子是没有道理的。如果它确实是多对多,那么它就是一个网络,如果一个孩子只有一个父母,那么它就是一个层次结构。

对于前者,我不确定以这种方式可视化它们有什么好处。您如何想象一个有多个父母的孩子?

对于后者,为什么不使用带有自定义项模板的 TreeView 呢?它自动处理所有层次结构的东西。中继器的问题在于,如果您没有动态地执行它们(在代码中创建它们),那么嵌套级别是固定的,您无法随心所欲地进行嵌套。动态地执行它们会起作用,但会带来开销。

我不太确定你到底想实现什么目标。也许提供一些有关您需要看到的最终结果的更多详细信息会有所帮助。

A Parent-Child relationship, which is many-to-many? This doesn't make sense, at least calling them a parent and a child doesn't make sense. If it is really many-to-many, it's a network, if a child only has ONE parent, then it is a hierarchy.

With the former, I'm not sure visualizing them in that way is any good. How do you visualize a child with more than one parent?

With the latter, why not use a TreeView with a custom item template? It handles all the hierarchy stuff automatically. The problem with repeaters is that if you are not doing them dynamically (creating them in code), then the level of nesting is fixed and you cannot go as much as you want. Doing them dynamically would work, but would bring overhead.

I'm not very sure what exactly you are trying to accomplish. Maybe providing some more details about the end-result you need to see would be helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文