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();
}
本文介绍了一个使用ASP.NET实现的动态下拉框功能示例。该示例通过TextBox的文字变化触发数据库查询,更新DropDownList的内容。具体实现包括:设置TextBox的AutoPostBack属性为true,定义TextChanged事件处理函数TextBox1_Changed,在该函数中构造SQL查询语句并绑定到DropDownList。
186

被折叠的 条评论
为什么被折叠?



