处理列过滤器服务器端事件
Contents
[
Hide
]
数据筛选可能是使用最广泛的 Excel 功能,它允许您根据特定条件筛选数据。过滤后的数据只显示符合条件的行,隐藏不符合条件的行。
Aspose.Cells.GridWeb 组件提供了使用其界面执行数据过滤的能力。为了扩展其功能,Aspose.Cells.GridWeb 组件还提供了两个事件,可以作为通过 GridWeb UI 完成的过滤机制的回调。
在应用列过滤器时处理服务器端事件
有两个主要事件,详述如下。
- OnBeforeColumnFilter:在过滤器将应用于列之前触发。
- OnAfterColumnFilter:在列上应用过滤器后触发。
这是 Aspose.Cells.GridWeb 组件的 ASPX 脚本,用于添加和分配上述事件。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
<acw:GridWeb ID="GridWeb1" runat="server" | |
OnBeforeColumnFilter="GridWeb1_BeforeColumnFilter" | |
OnAfterColumnFilter="GridWeb1_AfterColumnFilter"> | |
</acw:GridWeb> |
这些事件可用于获取有关过滤过程的有用信息,例如必须应用过滤器的列索引和值。以下代码段演示了如何使用 OnBeforeColumnFilter 事件来检索用户在 GridWeb UI 上选择用于过滤的列索引和值。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
protected void GridWeb1_BeforeColumnFilter(object sender, RowColumnEventArgs e) | |
{ | |
// Display the column index and filter applied | |
string msg = "[Column Index]: " + (e.Num) + ", [Filter Value]: " + e.Argument; | |
Label1.Text = msg; | |
} |
另一方面,如果需要在应用过滤器后获取过滤行数,则可以使用 OnAfterColumnFilter 事件,如下所示。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
protected void GridWeb1_AfterColumnFilter(object sender, RowColumnEventArgs e) | |
{ | |
string hidden = ""; | |
int headrow = 0; | |
int maxrow = GridWeb1.WorkSheets[0].Cells.MaxRow; | |
int count = 0; | |
// Iterate all worksheet rows to find out filtered rows | |
for (int i = headrow + 1; i <= maxrow; i++) | |
{ | |
if (GridWeb1.WorkSheets[0].Cells.Rows[i].Hidden) | |
{ | |
hidden += "-" + (i + 1); | |
} | |
else | |
{ | |
count++; | |
} | |
} | |
// Display hidden rows and visible rows count | |
string msg = "[Hidden Rows]: " + hidden + " [Visible Rows]: " + count; | |
Label1.Text = msg; | |
} |
查看所有介绍使用 GridWeb 事件以及有关如何处理这些事件的一些细节。