你好,可以通过以下方法实现,其中 Spread 方法及属性用法可以参考帮助文档,参考代码:
后台代码:
- /// <summary>
- /// 设置列头单元格和普通单元格数据类型为 CheckBoxCellType,同时设置客户端响应函数
- /// </summary>
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- this.FpSpread1.ActiveSheetView.AllowDelete = true;
- FarPoint.Web.Spread.CheckBoxCellType headerCheckBoxType = new FarPoint.Web.Spread.CheckBoxCellType();
- FarPoint.Web.Spread.CheckBoxCellType generalCheckBoxType = new FarPoint.Web.Spread.CheckBoxCellType();
- headerCheckBoxType.OnClientClick = "headerpostback()";
- generalCheckBoxType.OnClientClick = "generalpostback()";
- this.FpSpread1.ActiveSheetView.ColumnHeader.Columns[0].CellType = headerCheckBoxType;
- this.FpSpread1.ActiveSheetView.Columns[0].CellType = generalCheckBoxType;
- }
- }
复制代码 前台代码:
- <script type="text/javascript">
- /// <summary>
- /// 设置 button 失效
- /// </summary>
- function disabled() {
- return;
- }
- /// <summary>
- /// 响应列头 checkbox selectchange
- /// </summary>
- function headerpostback() {
- IsHead();
- CheckedCount();
- }
- /// <summary>
- /// 响应普通单元格 checkbox selectchange
- /// </summary>
- function generalpostback() {
- CheckedCount();
- }
- /// <summary>
- /// 查询 checkbox 选择数量
- /// </summary>
- function CheckedCount() {
- var deletebutton = document.getElementById("FpSpread1_Delete");
- var updatebutton = document.getElementById("FpSpread1_Update");
- var rowCount = FpSpread1.GetRowCount();
- var checkedNum = 0;
- for (var i = 0; i < rowCount; i++) {
- var row = i;
- var col = 0;
- var IsChecked = document.getElementById("FpSpread1_"+row.toString()+",0");
- if (IsChecked.checked) {
- checkedNum++;
- }
- }
- if (checkedNum == 1) {
- deletebutton.onclick = "disabled()";
- }
- if (checkedNum > 1) {
- updatebutton.onclick = "disabled()";
- }
- }
- /// <summary>
- /// 检查是否是列头单元格
- /// </summary>
- function IsHead() {
- var IsChecked = document.getElementById("FpSpread1_0,0,ch");
- var rowCount = FpSpread1.GetRowCount();
- if (IsChecked.checked) {
- for (var i = 0; i < rowCount; i++) {
- if (FpSpread1.Cells(i, 0).FpCellType == "CheckBoxCellType") {
- FpSpread1.SetValue(i, 0, "true", true);
- }
- }
- }
- }
- </script>
复制代码 |