前台html:

 

<html xmlns="http://www.w3.org/1999/xhtml"> 

 

 

<head runat="server">
    <title></title>
    <script src="jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
    <script src="jquery/autocomplete/jquery.autocomplete.min.js" type="text/javascript"></script>
    <link href="jquery/autocomplete/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $().ready(function() {

        $("#t_person").focus().autocomplete("ajax_do.aspx?page=texttishi&dotype=1", {
            max:1000,
            width: 150,
            selectFirst: false
        });
    });
        
    </script>
</head>
<body>
    <form />
    </div>
    </form>
</body>
</html>

 

后台(ajax_do.aspx.cs):

 

        using (SqlConnection con = new SqlConnection(GClass.connMyBo))
        {
            string strRet = "";
            string key = Request.Params["q"].ToString();
            string cmdSel = "select party_id from person where party_id like @key";
            SqlCommand cmd = new SqlCommand(cmdSel, con);
            con.Open();
            cmd.Parameters.AddWithValue("key", "%" + key + "%");
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                strRet +=reader[0].ToString()+"\n";
            }
            Response.Write(strRet);
        }

 

备注:

autocomplete默认的关键字是q,后台可以直接用Request.Params["q"]来获取当前输入文本框的值。

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2021-06-04
  • 2022-12-23
猜你喜欢
  • 2021-11-22
  • 2021-08-07
  • 2021-09-17
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案