是否有可能做定制的ASP.NET ListView控件分组? [英] Is it possible to do custom grouping in the ASP.NET ListView control?

查看:223
本文介绍了是否有可能做定制的ASP.NET ListView控件分组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你想要做的基于数据源的项目的性质分组只能定义在ListView一个GroupItemCount,但什么?排序方式一个特设小组。数据源进行排序这个属性。

You can only define a GroupItemCount in the ListView, but what if you want to do grouping based on a property of the items in the data source? Sort of an ad-hoc group by. The data source is sorted on this property.

我见过一些例子,在ItemTemplate一些标记是有条件的,但我想利用GroupTemplate如果可能的话。

I have seen some examples where some markup in the ItemTemplate was conditionally show, but I want to leverage the GroupTemplate if possible.

这可能吗?

推荐答案

当我不得不在一个中继我在ItemTemplate Literal控件这样做基本的添加组标题:

When I had to add basic group headings in a repeater I did so with a Literal control in the ItemTemplate:

<asp:Literal runat="server" Text='<%# GetGroupHeading(Eval("Group")) %>' />

在code中的'GetGroupHeading'方法保持跟踪previous组标题,并送回'&LT; H2基团名称&LT; / H&GT;',或一个空字符串,如果我们在同一个集团为previous项目。正如我所说,虽然,我这样做的一个中继器,所以不知道这是否将涉及您所需要的一个ListView

The 'GetGroupHeading' method in the code kept track of the previous group heading and sent back '<h2>Group Name</h2>', or an empty string if we were on the same group as the previous item. As I said though, I did this on a Repeater, so not sure if it will cover what you need for a ListView.

这篇关于是否有可能做定制的ASP.NET ListView控件分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆