找回密码
 立即注册

QQ登录

只需一步,快速开始

iceman

社区贡献组

270

主题

1万

帖子

1万

积分

社区贡献组

积分
19311

活字格认证微信认证勋章元老葡萄

iceman
社区贡献组   /  发表于:2011-11-24 16:24  /   查看:9422  /  回复:4
这篇文章介绍使用 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 并设置相关属性。
  1. FarPoint.Web.Spread.Extender.AutoCompleteCellType ac = new FarPoint.Web.Spread.Extender.AutoCompleteCellType();
  2.             ac.CompletionInterval = 1;
  3.             ac.DelimiterCharacters = ";, :";
  4.             AjaxControlToolkit.TextBoxWatermarkExtender twe = new AjaxControlToolkit.TextBoxWatermarkExtender();
  5.             twe.WatermarkText = "输入'S'测试...";
  6.             ac.Extenders.Add(twe);
  7.             ac.FirstRowSelected = true;
  8.             ac.ServicePath = "WebService1.asmx";
  9.             ac.ServiceMethod = "GetAllNames";
  10.             ac.MinimumPrefixLength = 1;
  11.             ac.EnableCaching = true;
  12.             ac.ShowEditor = true;
  13.             FpSpread1.ActiveSheetView.Cells[0, 0].CellType = ac;
复制代码
2.        创建 WebMethod 提供自动输入数据。
  1.     [System.Web.Script.Services.ScriptService]
  2.     public class WebService1 : System.Web.Services.WebService
  3.     {
  4.         [WebMethod]
  5.         public string[] GetAllNames(string prefixText, int count)
  6.         {
  7.             ArrayList filteredList = new ArrayList();
  8.             string[] names = { "AzamSharp", "Scott", "Alex", "Mary", "John", "Ali", "Sam", "Sammy" };
  9.             foreach (string name in names)
  10.             {
  11.                 if (name.ToLower().StartsWith(prefixText.ToLower()))
  12.                     filteredList.Add(name);
  13.             }
  14.             return (string[])filteredList.ToArray(typeof(string));
  15.         }     
  16.     }
复制代码
效果图:

png

png


下面是使用:AutoCompleteCellType 演示 Demo:
开 发 环 境:VS2010 + Srpead for ASP.NET V5.0.3524.2008
AutoCompleteCellType.zip (2.98 MB, 下载次数: 695)

4 个回复

倒序浏览
enthusiasm
新手上路   /  发表于:2014-10-17 11:16:00
沙发
运行示例代码可以得到“自动完成"的效果。
但是,自己创建的项目中却无法得到结果;为此单独建了两个项目来测试,并且代码和文件命名都做到了与示例一致,仍然无法看到应有的效果。
望解惑
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-10-17 12:08:00
板凳
回复 2楼enthusiasm的帖子

根据当前信息还无法确认问题所在,是否按照链接中的 提示http://gcdn.gcpowertools.com.cn/showtopic.aspx?topicid=2992 做准备工作?
回复 使用道具 举报
enthusiasm
新手上路   /  发表于:2014-10-17 12:23:00
地板
感谢回复,在发此问题前,已经按贴子中的说明做好准备工作了。
开发环境为:VS2013, framework4.5, win7 64位
FarPoint.Web.Spread.Extender的版本为7.40.20141.0
AjaxControlToolkit的版本为:3.0.30930.0
WebServices可以正常调用,并返回正常结果。输入s,返回s起头的字符

目前情况为:在表格中点击并输入字符s后,没有任何反应。
有什么办法调试此功能吗,以便知道在哪个环节出现的问题 ?
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-10-17 18:57:00
5#
回复 4楼enthusiasm的帖子

抱歉,目前确实没有办法确定您的问题。
如果运行附件demo没有问题,可以对比两个工程之前的差异,或者直接引用附件中的文件到你的项目中使用。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部