---
title: "ASP.NET中通过文本框的输入实现\"拼音码\"动态查询的效果"
author: "mywebcode"
date: "2008-11-16T12:47:00Z"
tags: []
slug: "asp-net"
draft: false
lastmod: "2013-05-08T10:14:43Z"
id: 1862528
url: "https://mywebcode.iteye.com/blog/1862528"
---

HTML核心代码如下:

&lt;asp:TextBox ID="TextBox1" runat="server" Style="position: relative" Width="200px"  
AutoPostBack="true" OnTextChanged="TextBox1\_Changed"&gt;&lt;/asp:TextBox&gt;  
&lt;asp:Button ID="Button1" runat="server" Style="left: 400px; position: relative; top: 0px"  
Text="查询" OnClick="Button1\_Click" /&gt;  
&lt;asp:DropDownList ID="DropDownList1" runat="server" Style="position: relative" Width="200px"  
CausesValidation="True" DataTextField="课程名称"&gt;  
&lt;/asp:DropDownList&gt;&lt;/td&gt;

C#核心代码如下:

protected void TextBox1\_Changed(object sender, EventArgs e)  
{  
SqlDataSource2.SelectCommand = "SELECT 课程名称 FROM course WHERE pinyima LIKE '"+TextBox1.Text+"%'";  
DropDownList1.DataSource = SqlDataSource2;  
DropDownList1.DataBind();  
DropDownList1.Dispose();  
}