I am working with two controls:
- list box
- text box
The list box is populated with data from the database. What I want to achieve is: as I type any letter in the text box, the list box should be filtered accordingly without the need for pressing Enter or Tab keys at the end. Unfortunately, this doesn't work by default and requires an additional key press.
Is there a solution to this problem using ASP.NET?
When a letter is typed into the text box, the list box should update instantly based on the input.
I currently have a listbox implemented, but in other pages, I am using a gridview.
Example code snippet:
<asp:Label ID="lbl_englishTitle" runat="server" CssClass="subtitle"
Text="Searching by English title:"></asp:Label>
<asp:TextBox ID="txt_filterByEnglishTitle" runat="server" AutoPostBack="True"
OnTextChanged="txt_filterByEnglishTitle_TextChanged"></asp:TextBox>
<!-- GridView example -->
... (omitted for brevity) ...
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
SelectMethod="GetAllPrograms" DeleteMethod = "Delete"
TypeName="Managers.Program" UpdateMethod="Save">
<DeleteParameters>
... (deleted parameters)
</DeleteParameters>
<UpdateParameters>
... (deleted parameters)
</UpdateParameters>
</asp:ObjectDataSource>`
Code-behind logic:
protected void txt_filterByEnglishTitle_TextChanged(object sender, EventArgs e)
{
gv_viewPrograms.DataSourceID = null;
gv_viewPrograms.DataSourceID = ObjectDataSource3.ID;
gv_viewPrograms.DataBind();
chb_allPrograms.Checked = false;
// txt_filterByEnglishTitle.Text = string.Empty;
txt_filterByEnglishTitle.Focus();
}