zoukankan      html  css  js  c++  java
  • ashx+jquery+autocomplete.js实现自动填充

    前台页面代码:

    <script type="text/javascript" src="../js/jquery.js" ></script>
    <script type="text/javascript" src="../js/jquery.autocomplete.js"></script>
    <script src="../js/thickbox.js" type="text/javascript"></script>
     <link href="../css/thickbox.css" rel="stylesheet" type="text/css" />
    <link type="text/css" href="../css/jquery.autocomplete.css"  rel="Stylesheet"/>
    <script type="text/javascript">
       //获取企业输入框ID
        var txtCorporation = "#<%=txtCorporation.ClientID %>";
       
        function findValue(li)
         { 
            if (li == null) return alert("No match!");
            if (!!li.extra)
            var sValue =unescape(li.extra[0]);
         
        }
        function selectItem(li)
         {
            findValue(li);
         }
      
        $(document).ready(function()
         {
           
            $(txtCorporation).autocomplete("ListCorporation.ashx",
              {
                delay: 10,
                minChars: 1,
                matchSubset: 1,
                cacheLength: 1,
                onItemSelect: selectItem,
                onFindValue: findValue,
                autoFill: true,
                maxItemsToShow: 20
            });
        });   
    </script>

    <div>

    <asp:TextBox id="txtCorporation" runat="server" ></asp:TextBox>

    </div>

     后台页面代码:

    <%@ WebHandler Language="C#" Class="ListCorporation" %>

    using System;
    using System.Web;
    using System.Text;
    using System.Data;
    public class ListCorporation :
        IHttpHandler {
       
        public void ProcessRequest (HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (context.Request.QueryString["q"] != null)
            {
                string key =context.Request.QueryString["q"];
                context.Response.Write(GetCorporationList(key));
            }
          
           
        }
        public string GetCorporationList(string key)
        {
            com.hbwl.BLL.base_Corporation ListCorporation = new com.hbwl.BLL.base_Corporation();
            StringBuilder strWhere = new StringBuilder("1=1");
            strWhere.Append(" and CorporationName like '%").Append(key).Append("%'");
            DataTable dt = ListCorporation.GetList(10,1,strWhere.ToString()).Tables[0];
            string result = "";
               if(dt.Rows.Count>0)
                {
               
                    StringBuilder items = new StringBuilder();
                    //历遍所有的海关编码数据
                    foreach (DataRow dr in dt.Rows)
                    {
                        items.Append(dr["CorporationName"].ToString() + "\n");
                    }
                    result = items.ToString();
                }
                return result;
        } 
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }

  • 相关阅读:
    document.createElement在IE和Firefox下的差异
    css3:基础知识
    XMLTProcessor根据XSLT样式规则将节点转换为document对象
    Sql:查看数据库表和表结构的语句
    前端性能优化方法总结
    vue-resource 设置请求的参数以formData形式以及设置请求的过滤器
    vuex
    vue 随笔3
    vuex
    vue随笔2
  • 原文地址:https://www.cnblogs.com/doublecc/p/1617381.html
Copyright © 2011-2022 走看看