回复 3楼raul1122的帖子
博客中通过前台的 FpSpread CallBack 方法调用后台的 ButtonCommand 事件实现自动触发:
- <script type ="text/javascript" language="javascript">
- function CategoryChanged() {
- var row = FpSpread1.ActiveRow;
- var col = FpSpread1.ActiveCol;
- FpSpread1.EndEdit();
- FpSpread1.UpdatePostbackData();
- FpSpread1.CallBack("CategoryChanged," + row.toString() + "," + col.toString());
- }
- </script>
复制代码
后台:
- /// <summary>
- /// Spread ButtonCommand 事件的处理函数,根据e.CommandName的值来决定相应的处理逻辑
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
- {
- switch (e.CommandName)
- {
- case "CategoryChanged":
-
- // 取到选择的产品类别,作为产品名称列的查询条件
- Point cell = (Point)e.CommandArgument;
- int categoryid = Convert.ToInt32(this.FpSpread1.ActiveSheetView.Cells[cell.X, cell.Y].Value.ToString());
-
- // 指定产品列相应单元格的CellType
- DataSet ds = GetDataSource();
- DataView product = ds.Tables["Products"].DefaultView;
- product.RowFilter = string.Format("CategoryID = {0}", categoryid);
- ComboBoxCellType ctProduct = new FarPoint.Web.Spread.ComboBoxCellType();
- ctProduct.DataSource = product;
- ctProduct.DataTextField = "Name";
- ctProduct.DataValueField = "ID";
- ctProduct.UseValue = true;
- FpSpread1.ActiveSheetView.Cells[cell.X, cell.Y + 1].CellType = ctProduct;
-
- break;
- default:
- break;
- }
-
- }
复制代码 |