• ajaxToolKit autoCompleteExtender简单例子


    ajaxToolKit中有个autoCompleteExtender对TextBox的扩展,能实现在文本框输入时有下拉框提示。效果不错。使用AjaxToolKit需要安装asp.net的ajax扩展工具:官方文档,然后引用DLL。前台如下:

    <asp:TextBox ID="txtID" runat="server"></asp:TextBox>
    <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
    TargetControlID
    ="txtID"
    ServicePath
    ="autoCompExtenderServer.asmx"
    ServiceMethod
    ="GetData"
    CompletionSetCount
    ="10"
    FirstRowSelected
    ="true"
    MinimumPrefixLength
    ="1"
    >
    </asp:AutoCompleteExtender>
    其中TargetControlID表示绑定的TextBox

    ServicePath:服务路径

    ServiceMethod:自动提示的方法名

    CompletionSetCount:显示的条数

    FirstRowSelected:是否自动选择到提示的第一行

    MinimumprefixLength:输入多少个字时开始提示;

    autoCompExtenderServer.asmx后台代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Runtime.Serialization;
    using System.Web.Script.Serialization;
    namespace auotoCompleteText
    {
    /// <summary>
    /// autoCompExtenderServer 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo
    = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(
    false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    public class autoCompExtenderServer : System.Web.Services.WebService
    {

    [WebMethod]
    public string[] GetData(string prefixText, int count)
    {
    string[] data = new string[10000];
    for (int i = 0; i < data.Length; i++)
    data[i]
    = i.ToString("0000");
    return data.Where(p => p.IndexOf(prefixText) >= 0).Take(count).ToArray();
    }
    }
    }
    注意这里的两个参数:prefixText,count都不能改变。

    参考资料:http://moosdau.blog.163.com/blog/static/43711282008824113942459/

  • 相关阅读:
    elasticseacth基础操作--QueryBuilders的使用
    并发编程(八)并发安全
    redis集群 相关
    并发编程(七)线程池
    PMP--综合考试知识点,持续更新中。。。
    常用正则表达式
    测试计划
    ACC(Attribute Component Capability) 即特质,组件,能力
    LockScreen
    Custom Window
  • 原文地址:https://www.cnblogs.com/xinjian/p/1886283.html
Copyright © 2020-2023  润新知