I am new to c# , i have one TextBox and one gridview when user type something in Textbox to search, the gridview is filled succesfully when clicked on search button.
But my concern is instaed of search button use ENTER KEY TO search data in gridview.
private void textBox3_TextChanged(object sender, KeyPressEventArgs e1, EventArgs e)
{
if (e1.KeyCode == Keys.Enter)
{
string sql = "[DocEntry],[JobCardNo],[ITEMNAME],[OD] ,[PlanQty],
[FinalInspectionRemarks] ,[OrderDate] ,[Division]
WHERE JobCardNo ='" + textBox3.Text.ToString() + "'";
SqlDataAdapter da = new SqlDataAdapter(sql, objConn1); DataSet ds = new DataSet();
objConn1.Open();
da.Fill(ds, "ProductionInventoryReport");
dataGridView1.DataSource = ds; //dataGridView1.DataBind();
dataGridView1.DataMember = "ProductionInventoryReport";
objConn1.Close(); e1.Handled = true;
}
}
I have tried this but not working
Instead of TextChanged event do it on KeyPress event.
First attach the event to the textbox, either in designer or in code like:
Then
Its better if you extract the search code to a separate method and then call the same method against your search button and KeyPress event.