zoukankan      html  css  js  c++  java
  • jquery autocomplete实现读取sql数据库自动补全TextBox

    转自我本良人 原文 jquery autocomplete实现读取sql数据库自动补全TextBox

    项目需要这样子一个功能,其他部门提的意见,只好去实现了哦,搞了好久才弄出来,分享一下。

    1.前台页面

        <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>  
          
        <!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 id="Head1" runat="server">  
            <title></title>  
            <script src="jquery-1.4.1-vsdoc.js" type="text/javascript"></script>  
            <script src="jquery.autocomplete.js" type="text/javascript"></script>  
            <link href="jquery.autocomplete.css" type="text/css" rel="stylesheet" />  
            <script language="javascript" type="text/javascript">  
                $(document).ready((function ()  
                {  
                    $("#txtUser").autocomplete("GetCode.aspx");  
                }  
        ));  
            </script>  
        </head>  
        <body>  
            <form id="form1" runat="server">  
                <div>  
                    用户名:  
                    <asp:TextBox ID="txtUser" runat="server"></asp:TextBox>  
                </div>  
            </form>  
        </body>  
        </html>  

    2.GetCode.aspx

    前台为空

    后台代码:

        using System;  
        using System.Collections.Generic;  
        using System.Linq;  
        using System.Web;  
        using System.Web.UI;  
        using System.Web.UI.WebControls;  
        using System.Data;  
        using System.Data.SqlClient;  
          
        public partial class GetCode : System.Web.UI.Page  
        {  
            protected void Page_Load(object sender, EventArgs e)  
            {  
                if (Request.QueryString["q"] != null)  
                {  
                    string key = Request.Params["q"].ToString();  
                    string result = "";  
                    SqlHelp sql = new SqlHelp();  
                    string str = "select top 15 CustomCode from tCustomList where CustomCode like '" + key + "%'";  
                    SqlDataReader dr = sql.ExecuteReader(str);  
                    while (dr.Read())  
                    {  
                        result += dr["CustomCode"].ToString() + "
    ";  
                    }  
                    dr.Dispose();  
                    sql.SqlClose();  
                    if (result == "")  
                        result = "not exists";  
                    Response.Write(result);  
                }   
            }  
        }  

    3. jquery.autocomplete.js

    Download from jquery.autocomplete.js.rar

  • 相关阅读:
    118. 杨辉三角
    1054. 距离相等的条形码
    面试题 02.01. 移除重复节点
    289. 生命游戏
    KONGA下的HAMC插件功能 --JAVA代码实现
    JPA
    Spring Cloud概述
    Spring框架分为哪七大模块,各模块的主要功能作用是什么
    ActiveMQ
    新手也能看懂,消息队列其实很简单
  • 原文地址:https://www.cnblogs.com/arxive/p/6251117.html
Copyright © 2011-2022 走看看