How to automatically search with out clicking Button

帅比萌擦擦* 提交于 2020-03-06 08:21:59

问题


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


回答1:


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);
    }
}


来源:https://stackoverflow.com/questions/40002949/how-to-automatically-search-with-out-clicking-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!