我有一个列表视图,其中包含来自azure db的数据。我需要根据textBox中的输入过滤它而不点击任何搜索按钮。每次插入或删除文本框中的新字符后,都应过滤列表。如何在我的ASP.Net Web应用程序(.NET Framework)中执行此操作? 我填写列表的代码(工作完美):
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindListView();
}
}
protected void SearchTextBox_TextChanged(object sender, EventArgs e)
{
String input = searchTextBox.Text;
//TODO - filter
}
private void BindListView(){
try
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "contactsdbnatalie.database.windows.net";
builder.UserID = "******";
builder.Password = "******";
builder.InitialCatalog = "contactsdb";
using (sqlConnection = new SqlConnection(builder.ConnectionString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT ContactName, ContactNumber FROM Contacts";
cmd.Connection = sqlConnection;
using (sqlAdapter = new SqlDataAdapter(cmd))
{
dataTable = new DataTable();
sqlAdapter.Fill(dataTable);
contactsListView.DataSource = dataTable;
contactsListView.DataBind();
}
}
}
}
catch (SqlException exception)
{
Console.WriteLine(exception.ToString());
}
}