Hi Richa,
I have created one sample that full-fill your requirement. I have created in two way please check below.
1. Code Using button text
private void btnSearch_Click(object sender, EventArgs e)
{
this.btnSearch.Text = "Loading...";
this.btnSearch.Enabled = false;
Thread.Sleep(2000);
this.btnSearch.Enabled = true;
string ddlText = this.cbCategory.Text.Trim();
string query = "SELECT [CategoryID],[CategoryName] FROM [Categories] WHERE [CategoryName] LIKE '%' + @CategoryName + '%'";
string constr = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query, conn))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
cmd.Parameters.AddWithValue("@CategoryName", ddlText);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
this.cbCategory.DataSource = dt;
this.cbCategory.DisplayMember = "CategoryName";
this.cbCategory.ValueMember = "CategoryID";
this.btnSearch.Text = "Search";
}
}
}
}
2. Code using cursor
private void btnSearch_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
string ddlText = this.cbCategory.Text.Trim();
string query = "SELECT [CategoryID],[CategoryName] FROM [Categories] WHERE [CategoryName] LIKE '%' + @CategoryName + '%'";
string constr = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query, conn))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
cmd.Parameters.AddWithValue("@CategoryName", ddlText);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
this.cbCategory.DataSource = dt;
this.cbCategory.DisplayMember = "CategoryName";
this.cbCategory.ValueMember = "CategoryID";
this.btnSearch.Text = "Search";
this.btnSearch.Enabled = true;
}
}
}
Cursor.Current = Cursors.Default;
}
Screenshot