新手第一次写 一个文本框输入文字后智能提示相似的项在下面显示。
C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class test_znts_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["type"] != null && Request.QueryString["type"].Equals("exec"))
{
Response.ClearContent(); Response.Write(str1()); Response.End();
}
}
protected string str1()
{
string str = "";
string s = Request.QueryString["txt"].ToString();
if (s == "")
{ return ""; }
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConn"].ConnectionString);
string sql = "select distinct code from protestcode where code like '" +s+ "%'";
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
sda.Fill(ds, "table");
int count = Convert.ToInt32(ds.Tables["table"].Rows.Count);
//StringBuilder sb = new StringBuilder();
for (int i = 0; i < count; i++)