这篇文章介绍使用 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