peter peter - 1 month ago 11
ASP.NET (C#) Question

How to automatically search with out clicking Button

i have few text boxes and dropdown boxes in a search window,and when click search button it will display data on gridview based on value selection in controls.Now what i want is even without clicking on search button it will display data automatically in gridview based on control selection.How to achieve it.I am posting small snippet contains only text box.

UI



<div>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
</div>
<div>
<asp:Button ID="Button1" runat="server" Text="Search" OnClick="Button1_Click" />
</div>
<div>
<asp:GridView ID="grdresults" runat="server"></asp:GridView>
</div>


CS



protected void Button1_Click(object sender, EventArgs e)
{
try
{
LoadData();
BindGrid();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}


The above LoadData(); method will create the search criteria (
where
clause for oracle query) and will get data in to
datatable
which will be in
session
,Then BindGrid(); will assign data to
grdresult
gridview.Search is working fine by clicking the button,but i want it in an automated way

Answer

UI

<asp:TextBox ID="txtFirstName" runat="server" TextChanged="txtFirstName_TextChanged"></asp:TextBox>

CS

protected void txtFirstName_TextChanged(object sender, EventArgs e)
{
    try
    {
        LoadData();
        BindGrid();
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }
}
Comments