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

  • 相关阅读:
    简单测试AF3.0.4
    好玩的Mac键盘
    黑盒测试和白盒测试
    iOS开发之原生二维码生成与扫描
    Swift
    JavaScript null and undefined
    java防止表单重复提交
    Java http post
    Redhat 6.5 x64 下载地址
    Spring 官方下载地址(非Maven)
  • 原文地址:https://www.cnblogs.com/arxive/p/6251117.html
Copyright © 2011-2022 走看看