Spread Ajax Extender 之旅-自动完成功能

发布时间:2012/11/14 00:11 发布者:葡萄城产品团队

返回博客中心

这篇文章介绍使用 AutoCompleteCellType 实现了自动输入功能。

关于使用 AutoCompleteCellType 的准备工作,请参考:
http://gcdn.grapecity.com/showtopic-2992.html

AutoCompleteCellType重要属性说明:
1.        CompletionInterval:获取或设置从web服务器中读取数据的时间间隔,单位为毫秒,默认值为 1000 毫秒。
2.        Extenders:获取 AutoCompleteCellType 关联的 AJAXControl Toolkit 控件。
3.        FirstRowSelected:获取或设置是否选中自动关联列表中的第一项。
4.        ServiceMethod:获取或设置提供关联选项的 WebService 函数。
5.        ServicePath:获取或设置提供关联选项的 WebService 文件路径。
6.        ShowEditor:获取或设置是否显示编辑器。

下面通过实例来展示如何使用 AutoCompleteCellType 实现自动输入功能。
1.        创建 AutoCompleteCellType 并设置相关属性。

 
FarPoint.Web.Spread.Extender.AutoCompleteCellType ac = new FarPoint.Web.Spread.Extender.AutoCompleteCellType();

            ac.CompletionInterval = 1;

            ac.DelimiterCharacters = ";, :";

            AjaxControlToolkit.TextBoxWatermarkExtender twe = new AjaxControlToolkit.TextBoxWatermarkExtender();

            twe.WatermarkText = "输入'S'测试...";

            ac.Extenders.Add(twe);

            ac.FirstRowSelected = true;

            ac.ServicePath = "WebService1.asmx";

            ac.ServiceMethod = "GetAllNames";

            ac.MinimumPrefixLength = 1;

            ac.EnableCaching = true;

            ac.ShowEditor = true;

            FpSpread1.ActiveSheetView.Cells[0, 0].CellType = ac;

复制代码
2.        创建 WebMethod 提供自动输入数据。
    [System.Web.Script.Services.ScriptService]

    public class WebService1 : System.Web.Services.WebService

    {

        [WebMethod]

        public string[] GetAllNames(string prefixText, int count)

        {

            ArrayList filteredList = new ArrayList();

            string[] names = { "AzamSharp", "Scott", "Alex", "Mary", "John", "Ali", "Sam", "Sammy" };

            foreach (string name in names)

            {

                if (name.ToLower().StartsWith(prefixText.ToLower()))

                    filteredList.Add(name);

            }

            return (string[])filteredList.ToArray(typeof(string));

        }     

    }

复制代码



下面是使用:AutoCompleteCellType 演示 Demo:
开 发 环 境:VS2010 + Srpead for ASP.NET V5.0.3524.2008

AutoCompleteCellType.zip (2.98 M, 下载次数:30)

关于葡萄城

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

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