本文展示了如何通过单击 GridWeb 的内置保存命令按钮以外,还可以通过单击通用 ASP.NET 按钮(Web 控件)来向服务器提交数据。本文目的是展示 Aspose.Cells.GridWeb 的灵活性。此外,本文还使用了 Aspose.Cells.GridWeb 在客户端脚本中提供的特殊函数。
使用 ASP.NET 按钮提交 Grid 数据
Aspose.Cells.GridWeb 提供了三个内置按钮(提交、保存和撤销)。在 GridWeb 中进行编辑后,用户可以在选项卡栏中单击提交或保存按钮,让 GridWeb 提交数据到服务器。如果用户单击一个工作表标签,GridWeb 控件将执行与内置命令按钮相同的任务。Aspose.Cells.GridWeb 还支持将此功能添加到通用的 ASP.NET 按钮控件上,但您需要向应用程序添加一些额外的代码。
1. 创建一个测试应用程序
打开 Visual Studio.NET IDE,并创建一个新的 ASP.NET Web Application 项目。创建完应用程序后,会添加一个默认的 WebForm1.aspx 页面到您的项目中。从工具箱中将 GridWeb 控件拖放到 Web Form 中。如果您在工具箱中找不到 GridWeb 控件,可以参考此页面:将 Aspose.Cells Grid 控件集成到 Visual Studio.NET 了解更多。在将 GridWeb 控件添加到 Web Form 后,还需从工具箱中将一个按钮 Web 控件拖放到 Web Form 中。
2. 在 Page_Load 事件中添加代码
现在,可以在 Web Form 的设计视图中双击 Page_Load 事件,VS.NET IDE 将自动带您到 Page_Load 事件处理程序,您需要使用按钮的 Attributes 集合来重写其 OnClick 事件。
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