Spread for ASP.NET 6.0中客户端删除是通过CommandBar上的删除按钮来实现的,默认状态下该操作一次只能删除一行数据,在实际需求中,我们往往需要一次删除多行数据。
点击客户端的“删除”按钮之后,会调用FpSpread.Delete()方法来完成的删除操作,要实现一次删除多行数据就需要改变Spread的默认行为,修改点击“删除”按钮之后的处理逻辑,这里将提供两种一次删除多行数据的实现方法:
第一种:使用CheckBox标记需要删除的行
1、将Spread第一列的单元格类型设置为CheckBoxCellType
- this.FpSpread1.ActiveSheetView.Columns[0].CellType = new FarPoint.Web.Spread.CheckBoxCellType();
复制代码
2、重写“删除”按钮的默认行为(服务端)
- protected override void Render(HtmlTextWriter writer)
- {
- WebControl delButton = FpSpread1.FindControl("Delete") as WebControl;
- if (delButton != null)
- {
- delButton.Attributes.Add("onclick", "MultiDlete();return false;");
- }
- base.Render(writer);
- }
复制代码
3、重写“删除”按钮的默认行为(客服端)
- <script language="javascript" type="text/javascript">
- function MultiDlete() {
- var ss = FpSpread("FpSpread1");
- if (ss != null) {
- ss.UpdatePostbackData();
- ss.CallBack("MultiDlete");
- }
- }
- </script>
复制代码
4、删除用户选择的数据行
- protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
- {
- if (e.CommandName.Equals("MultiDlete"))
- {
- for (int r = FpSpread1.ActiveSheetView.RowCount - 1; r >= 0; r--)
- {
- var check = FpSpread1.ActiveSheetView.Cells[r, 0].Value;
- if (check != null && (Convert.ToInt32(check) == 1))
- {
- FpSpread1.ActiveSheetView.Rows.Remove(r, 1);
- }
- }
- }
- }
复制代码
第二种:删除用户选中的所有行
1、重写“删除”按钮的默认行为(服务端)
- protected override void Render(HtmlTextWriter writer)
- {
- WebControl delButton = FpSpread1.FindControl("Delete") as WebControl;
- if (delButton != null)
- {
- delButton.Attributes.Add("onclick", "MultiDlete();return false;");
- }
- base.Render(writer);
- }
复制代码
2、重写“删除”按钮的默认行为(客服端)
- <script language="javascript" type="text/javascript">
- function MultiDlete() {
- var ss = FpSpread("FpSpread1");
- if (ss != null) {
- ss.UpdatePostbackData();
- ss.CallBack("MultiDlete");
- ss.ClearSelection();
- }
- }
- </script>
复制代码
3、删除用户选择的数据行
- protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
- {
- if (e.CommandName.Equals("MultiDlete"))
- {
- CellRange[] cRanges = FpSpread1.ActiveSheetView.GetSelections();
- for (int i = cRanges.Length -1; i >= 0; i--)
- {
- FpSpread1.ActiveSheetView.RemoveRows(cRanges[i].Row, cRanges[i].RowCount);
- }
- }
- }
复制代码
源码下载:VS2010 + Spread 6.0.3505
4881_CustomDelete.zip
(11.51 KB, 下载次数: 1607)
|
|