0
回答
怎样使用autocomplete做简单的搜索提示,根据数据库
华为云实践训练营,热门技术免费实践!>>>   

 

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="js/jquery.js"></script>
    <script src="js/jquery-ui.js"></script>
    <link href="js/jquery-ui.css" rel="stylesheet" />
    <script>
        $(function () {
           // var projects = [{ value: "张三" }, { value: "李四" }, { value: "李四111" }];
            //var projectes = Session["a"];
           
                $("#Text1").autocomplete({
                    source: "WebForm2.aspx",
                }).data("ui-autocomplete")._renderItem = function (ul, item) {

                    return $("<li>").append("<a>" + item.userName + "</a>").appendTo(ul);
                }
          
           
        })
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <input type="text"  name="ss" id="Text1" name="q" onblur="Getss()"/>
        </div>
    </form>
</body>
</html>

        protected void Page_Load(object sender, EventArgs e)
        {
            DBHelper db = new DBHelper();
           // string ss = Session["tex"].ToString();
             string aa= Request.QueryString["q"];
            string sql = string.Format("select userName from tb_user where userName like '%{0}%'",aa);
          
            DataSet ds = db.Select(sql);
            if (ds.Tables[0].Rows.Count > 0)
            {
                string info = JsonConvert.SerializeObject(ds.Tables[0]);
                //Session["a"] = info;
                Response.Write(info);
            }

        }

举报
亚亚111
发帖于2个月前 0回/18阅
顶部