我想从我的数据库中获取我的文本框中的机场名称列表,例如当我在文本框中键入 Las 时。文本框应该给 lasvegas。
默认.aspx.cs:
public string listFilter = null;
protected void Page_Load(object sender, EventArgs e)
{
listFilter = BindName();
}
private string BindName()
{
try
{
SqlConnection con = new SqlConnection(@"Data Source=172.16.10.170;Initial Catalog=cbtsv;User ID=cbtsv;Password=cbtsvpass;");
con.Open();
DataTable ds = new DataTable();
using (SqlCommand cmd = con.CreateCommand())
{
SqlCommand com = new SqlCommand("select SearchKey from DTAirportCity where SearchKey like '%TextBox1.Text%'", con);
SqlDataAdapter sda = new SqlDataAdapter(com);
sda.Fill(ds);
}
StringBuilder output = new StringBuilder();
output.Append("[");
for (int i = 0; i < ds.Rows.Count; ++i)
{
output.Append("\"" + ds.Rows[i]["SearchKey"].ToString() + "\"");
if (i != (ds.Rows.Count - 1))
{
output.Append(",");
}
}
output.Append("];");
return output.ToString();
con.Close();
}
catch (Exception)
{
throw;
}
}
默认.aspx:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<title></title>
<script type="text/javascript">
function LoadList() {
var dt=null;
dt = <%=listFilter %>
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" OnLoad="LoadList()"></asp:TextBox>
<br />
</div>
</form>
问题:- LoadList() 函数不起作用。