具有可扩展组的分组Gridview

围绕网格视图或具有子网格视图的主题存在许多问题。 我考虑过这种方法,但对我来说这太过分了。 我能找到的最接近的问题是这一个: Grouped Gridview

不幸的是,尽管这对于如何创建分组行有一些建议,但它并没有使它们成为可折叠的。

我的要求是我希望用户看到分隔行的网格视图,例如

– 第1组
数据1 | 数据2 | 数据3
数据1 | 数据2 | 数据3
数据1 | 数据2 | 数据3
– 第2组
数据1 | 数据2 | 数据3
数据1 | 数据2 | 数据3
– 第3组
数据1 | 数据2 | 数据3
数据1 | 数据2 | 数据3
数据1 | 数据2 | 数据3
数据1 | 数据2 | 数据3

如果用户希望这样的观看,那么用户就可以:

+ GROUP 1
– 第2组
数据1 | 数据2 | 数据3
数据1 | 数据2 | 数据3
– 第3组
数据1 | 数据2 | 数据3
数据1 | 数据2 | 数据3
数据1 | 数据2 | 数据3
数据1 | 数据2 | 数据3

或这个:

+ GROUP 1
+ GROUP 2
+ GROUP 3

基本上所有分组行都包含在组中。 它们甚至不是真正合适的Gridview行。 实际的行是gridview,并且不需要任何进一步的向下钻取function。

我希望我的解决方案是可行的客户端,我有限制,我可以使用javascript或jQuery(包括jQuery-ui 1.8.8),但不能随意扩展我正在使用的AJAX工具包的数量。 我宁愿不必通过多组扩展回发来不断管理页面状态。

这是可以实现的吗? 有人能指出我可能会给我一个轻推的资源方向吗?

编辑:哦,是的,我忘了提。 基本gridview的行偶尔会有控件,包括但不限于:按钮,文本框,复选框和下拉列表。

由于您没有提供实际代码,因此我根据其他问题汇总了一个如何完成所需内容的示例。

另一个问题只是将文件放在服务器的驱动器C上,并按网格中的降序按创建时间对它们进行分组。 所以这里是转发器标记:

    

这是OnRowDataBound事件背后的代码; 用C#编写,因为你使用的是:

 private int month = -1; private int year = -1; protected void rpt_RowDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { //Binding to FileInfo objects. //Since we are grouping by CreationTime we need to check if it's time to create a new "group" //Is current month and year different from the value previously stored on the month and year variables? if (month != (e.Item.DataItem as FileInfo).CreationTime.Month || year != (e.Item.DataItem as FileInfo).CreationTime.Year) { month = (e.Item.DataItem as FileInfo).CreationTime.Month; year = (e.Item.DataItem as FileInfo).CreationTime.Year; //append the current group to the hidden variable "dataGroups" which will tell us quickly how many groups we have in total dataGroups.Value += (e.Item.DataItem as FileInfo).CreationTime.ToString("yyyMM") + ","; } //for every row; "stamp it" with this attribute since we'll use it on the client side with jQuery (e.Item.FindControl("tableItem") as HtmlTable).Attributes.Add("data-group", (e.Item.DataItem as FileInfo).CreationTime.ToString("yyyMM")); } } 

现在在客户端; 我们需要做一些jQuery魔术来构建可折叠面板。

     

现在,这些代码行产生了这样的:

在此处输入图像描述