Spread for ASP.NET 6.0 中提供了分组的功能,用户可以将某列拖动到分组栏中,以此来实现对数据的分组现实。
在某些时候,为了用户操作方便,我们希望一次性的展开所有分组,或者折叠所有分组,这时候我们可以通过下面的代码来实现该功能:
首先,初始化 Spread 控件:
- protected void Page_Load(object sender, EventArgs e)
- {
- if (IsPostBack)
- {
- return;
- }
- FpSpread1.ActiveSheetView.AllowPage = false;
- FpSpread1.ActiveSheetView.RowCount = 10;
- FpSpread1.ActiveSheetView.ColumnCount = 50;
- FpSpread1.ActiveSheetView.AllowGroup = true;
- FarPoint.Web.Spread.GroupInfo gi = new FarPoint.Web.Spread.GroupInfo();
- gi.BackColor = Color.LightSkyBlue;
-
- FarPoint.Web.Spread.GroupInfo gi2 = new FarPoint.Web.Spread.GroupInfo();
- gi2.BackColor = Color.LightGoldenrodYellow;
- FpSpread1.ActiveSheetView.GroupInfos.Add(gi);
- FpSpread1.ActiveSheetView.GroupFooterInfos.Add(gi2);
- FpSpread1.ActiveSheetView.GroupFooterVisible = true;
- FpSpread1.ActiveSheetView.GroupBarVisible = true;
- FpSpread1.ActiveSheetView.GroupBarHeight = 50;
- FpSpread1.ActiveSheetView.GroupBarText = "将列拖拽到这里进行分组!";
- FpSpread1.ActiveSheetView.Cells[0, 0, 3, 0].Value = 1;
- FpSpread1.ActiveSheetView.Cells[0, 1, 1, 1].Value = 1;
- FpSpread1.ActiveSheetView.Cells[2, 1, 3, 1].Value = 2;
- FpSpread1.ActiveSheetView.Cells[4, 0, 7, 0].Value = 2;
- FpSpread1.ActiveSheetView.Cells[8, 0, 9, 0].Value = 3;
- }
复制代码
添加“全部展开”和“全部折叠”功能的代码:
- protected void Button1_Click(object sender, EventArgs e)
- {
- ExpandAll(true);
- }
- protected void Button2_Click(object sender, EventArgs e)
- {
- ExpandAll(false);
- }
- private void ExpandAll(bool expanded)
- {
- FarPoint.Web.Spread.Model.GroupDataModel gdm = FpSpread1.ActiveSheetView.DataModel as FarPoint.Web.Spread.Model.GroupDataModel;
- if (gdm != null)
- {
- foreach (FarPoint.Web.Spread.Model.Group item in gdm.Groups)
- {
- item.Expanded = expanded;
- }
- }
- }
复制代码
运行截图:
2012-11-6 19-45-22.png
(51.71 KB, 下载次数: 301)
|
|