自定义 PopupCellType 实现方法之二

发布时间:2012/12/07 00:12 发布者:jian

返回博客中心

之前一篇关于 PopupCellType 单元格类型是使用 AjaxControlToolkit 提供的 ModalPopupExtender 实现的,不过有的用户反馈不想使用 AjaxControlToolkit ,希望提供另外的实现方法,本文主要结合 window.showModalDialog 来实现另外一种PopupCelltype.

基本思路和之前的基本相同,首先创建一个自定义的单元格类型 PopupCellType,并重写GetEditorControl方法,代码如下:

    public class PopupCellType : FarPoint.Web.Spread.GeneralCellType
    {

        public override Control GetEditorControl(string id, TableCell parent, FarPoint.Web.Spread.Appearance style, FarPoint.Web.Spread.Inset margin, object value, bool upperLevel)
        {
            Table table = new Table();
            table.CellPadding = 0;
            table.CellSpacing = 0;
            table.BorderStyle = BorderStyle.None;
            table.BorderWidth = new Unit(0, UnitType.Pixel);
            table.Width = new Unit(100, UnitType.Percentage);

            TableRow row = new TableRow();

            TableCell cell = new TableCell();
            cell.VerticalAlign = VerticalAlign.Middle;
            cell.HorizontalAlign = HorizontalAlign.Left;

            // 用户可以直接在 TextBox 中输入数据
            TextBox tb = new TextBox();
            tb.Width = new Unit(95, UnitType.Percentage);
            tb.Attributes.Add("ondblclick", "ShowPopupForm()");
            tb.Attributes.Add("PopupEditor", "PopupEditor");
            tb.ID = "PopupEditor1001";
            cell.Controls.Add(tb);
            row.Cells.Add(cell);

            table.Rows.Add(row);

            return table;
        }
    }

 

然后给使用该单元格类型的页面中添加 ShowPopupForm 的实现代码:

 

<script type="text/javascript" language="javascript">
        function ShowPopupForm() {
            FpSpread1.EndEdit();
            var text = FpSpread1.GetValue(FpSpread1.GetActiveRow(), FpSpread1.GetActiveCol());
            var myWindow = window.showModalDialog("PopupForm.aspx?searchkey=" + encodeURI(text), "请选中一个值!", "dialogWidth=600px;dialogHeight=300px;directories=0;channelmode=0;fullscreen=0;menubar=0;titlebar=1;center=1;help=0;status=0;toolbar=0;location=0");
            FpSpread1.SetValue(FpSpread1.GetActiveRow(), FpSpread1.GetActiveCol(), myWindow);
        }
    </script>

创建弹出对话框中显示的页面内容,并增加返回选中数据的前端JS代码:

 

<script type="text/javascript" language="javascript">
        function ReturnSelectedValue() {
            var text = FpSpread1.GetValue(FpSpread1.GetActiveRow(), FpSpread1.GetActiveCol());
            window.returnValue = text;
            window.close();
        }
    </script>

运行效果:

 

源码下载:

0000_Popup2.zip (12.01 kb)


关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网