zoukankan      html  css  js  c++  java
  • asp.net+ajax+WebServer 输入自动提示历史记录

    1. 新建一个vs项目

    2. 下载微软提供ajax控件扩展包:http://www.codeplex.com/AjaxControlToolkit.com下载

    注:根据vs的不同版本下载对应扩展包。

    3. 将下载下来的AjaxControlToolkit.dll文件添加到新建vs项目中(工具箱)

    4. 新建个WebServer页面

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Data;

    namespace BoxDataWeb
    {
        /// <summary>
        /// WebServiceSeek 的摘要说明
        /// </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 WebServiceSeek : System.Web.Services.WebService
        {
            [WebMethod]

           /*此处一定要注视掉*/
            //public string HelloWorld()
            //{
            //    return "Hello World";
            //}
            //历史数据
            public string[] HistoricalData(string prefixText)
            {
                //prefixText:输入关键字
                //Company:要检索的字段
                //VehideInfo:对应表
                Maticsoft.Web.Admin.DataBase db = new Maticsoft.Web.Admin.DataBase();
                DataSet ds = db.RunDataSetSQL("SELECT Company FROM VehideInfo where Company like '" + prefixText + "%'", "VehideInfo");
                List<string> items = new List<string>();
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    items.Add(dr["Company"].ToString());
                }
                return items.ToArray(); 
            }
        }
    }

    5. aspx页面如下:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="BoxDataWeb.WebForm2" %>

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <%--解释:1. TargetControlID:要绑定控件的ID,2. ServicePath:WebServer文件路径 3.ServiceMethod:WebServer文件中对应的方法  4. MinimumPrefixLength:输入第一个字符开始显示历史记录 --%>
            <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1" ServicePath="~/WebServiceCompanySeek.asmx" ServiceMethod="HistoricalData" MinimumPrefixLength="1" CompletionSetCount="20">
            </cc1:AutoCompleteExtender>
        </div>
        </form>
    </body>
    </html>

  • 相关阅读:
    [BZOJ2324][ZJOI2011]营救皮卡丘
    P4324 [JSOI2016]扭动的回文串
    P5068 [Ynoi2015]我回来了
    P4412 [SHOI2004]最小生成树
    bzoj3118: Orz the MST(线性规划+单纯形法)
    bzoj3265: 志愿者招募加强版(线性规划+单纯形法)
    bzoj3550: [ONTAK2010]Vacation(单纯形法+线性规划)
    uoj#179. 线性规划
    P2093 [国家集训队]JZPFAR(KDTree)
    P3538 [POI2012]OKR-A Horrible Poem
  • 原文地址:https://www.cnblogs.com/zhujp/p/2937361.html
Copyright © 2011-2022 走看看