asp.net 中继器中的嵌套列表

发布于 2024-09-24 18:21:06 字数 1285 浏览 1 评论 0原文

我有一个看起来像这样的中继器:

<HeaderTemplate>
    <div>
</HeaderTemplate>
<ItemTemplate>
<asp:PlaceHolder runat="server" id="plhContent"/>
</ItemTemplate>
<FooterTemplate>
    </div>
</FooterTemplate>

然后我有一个看起来像这样的数据集:

Title | Category
"Title1","Legal"
"Title2","Legal"
"Title3","Finance"
"Title4","Accounting"

数据集按类别排序。

我试图实现的输出是:

<div><!-- from headertemplate -->
    <div id="legal">
        <ul>
            <li>Title 1</li>
            <li>Title 2</li>
        </ul>
    </div><!--end legal div-->
    <div id="Finance">
        <ul>
            <li>Title 3</li>
        </ul>
    </div><!--end finance div-->
    <div id="Accounting">
        <ul>
            <li>Title 4</li>
        </ul>
    </div><!--end accounting div-->
</div><!-- from footertemplate -->

但是我真的很难理解逻辑。在我的代码中,我基本上得到了:

Add a bulleted list
Add a listitem

但这给行“title2”带来了问题,因为它不需要新的项目符号列表,它只需要在转发器的上一次迭代中将新的列表项添加到项目符号列表中。

我怎么可能做到这一点?

提前致谢 铝

I have a repeater which looks like so:

<HeaderTemplate>
    <div>
</HeaderTemplate>
<ItemTemplate>
<asp:PlaceHolder runat="server" id="plhContent"/>
</ItemTemplate>
<FooterTemplate>
    </div>
</FooterTemplate>

I then have a dataset that looks like:

Title | Category
"Title1","Legal"
"Title2","Legal"
"Title3","Finance"
"Title4","Accounting"

The dataset is sorted by the category.

And the output im trying to achieve is:

<div><!-- from headertemplate -->
    <div id="legal">
        <ul>
            <li>Title 1</li>
            <li>Title 2</li>
        </ul>
    </div><!--end legal div-->
    <div id="Finance">
        <ul>
            <li>Title 3</li>
        </ul>
    </div><!--end finance div-->
    <div id="Accounting">
        <ul>
            <li>Title 4</li>
        </ul>
    </div><!--end accounting div-->
</div><!-- from footertemplate -->

However I'm really struggling with the logic. Within my code i've essentially got:

Add a bulleted list
Add a listitem

But this poses a problem for the row "title2" because it doesnt require a new bulleted list, it just requires a new listitem to be added to the bulleted list in the previous iteration of the repeater.

How can i possibly do this?

Thanks in advance
Al

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

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

发布评论

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

评论(1

甜味拾荒者 2024-10-01 18:21:06

一种选择是创建某种临时结构来保存数据集的内容,以便转发器能够按照您需要的方式显示信息。

我正在考虑将其变成一个类别列表,每个类别将是一个项目列表。然后您像这样浏览 DataSet 项目(伪代码):

对于每个项目
如果类别列表中不存在类别
创建“类别项目”列表
将项目(标题)添加到列表中
将此列表添加到类别列表中
别的
找到类别
将项目(标题)添加到列表中

中继器应该能够处理它

An option would be to create some kind of temporary structure to hold the contents of the DataSet in a way that the Repeater will be able to handle to display the information the way you need it.

I'm thinking about turning it into a list of categories, and each category will be a list of items. Then you go through the DataSet items like so (pseudo-code):

for each item
if category does not exist in list of categories
create a list of "category items"
add the item (title) to the list
add this list to the list of categories
else
find the category
add the item (title) to the list

The repeater should then be able to handle it

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