HTML核心代码如下:
<asp:TextBox ID="TextBox1" runat="server" Style="position: relative" Width="200px" AutoPostBack="true" OnTextChanged="TextBox1_Changed"></asp:TextBox> <asp:Button ID="Button1" runat="server" Style="left: 400px; position: relative; top: 0px" Text="查询" OnClick="Button1_Click" /> <asp:DropDownList ID="DropDownList1" runat="server" Style="position: relative" Width="200px" CausesValidation="True" DataTextField="课程名称"> </asp:DropDownList></td>
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(); }