title: Search and display in gridview
body: <p>I've been working on this one since someone teaches me to use gridview to display my search result.</p>
  
  <p>My problem is, I can't even make it work, when I click or hit the search button, nothing happen. I have:</p>
  
  <p>-1 textbox for last name
  -2 dropdownlist for the province and city
  -and a search(trigger)button</p>
  
  <p>Here's what I've done so far:</p>
  
  <pre><code> public partial class Default : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              string constring = ConfigurationManager.ConnectionStrings["AccreString"].ConnectionString;
              SqlConnection conn = new SqlConnection(constring);
              DataTable dt = new DataTable("emed_province");
  
              using (conn)
              {
                  conn.Open();
                  SqlCommand comm = new SqlCommand("SELECT * FROM emed_province ORDER BY PROVINCE_NAME ASC", conn);
                  SqlDataAdapter adptr = new SqlDataAdapter(comm);
                  adptr.Fill(dt);
              }
  
              ddlProvince.DataSource = dt;
              ddlProvince.DataTextField = "PROVINCE_NAME";
              ddlProvince.DataValueField = "PROVINCE_CODE";
              ddlProvince.DataBind();
          }
      }
  
      protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
      {
          string constring = ConfigurationManager.ConnectionStrings["AccreString"].ConnectionString;
          SqlConnection conn = new SqlConnection(constring);
          DataTable dt = new DataTable("emed_province");
  
          using (conn)
          { 
              conn.Open();
              SqlCommand comm = new SqlCommand("SELECT * FROM emed_city WHERE PROVINCE_CODE =@pcode", conn);
              comm.Parameters.AddWithValue("@pcode", ddlProvince.SelectedValue);
              SqlDataAdapter adptr = new SqlDataAdapter(comm);
              adptr.Fill(dt);
  
              SqlParameter param = new SqlParameter();
              param.ParameterName = "@pcode";
              param.Value = ddlProvince;
  
              comm.Parameters.Add(param);
          }
  
          ddlCity.DataSource = dt;
          ddlCity.DataTextField = "CITY_NAME";
          ddlCity.DataValueField = "CITY_CODE";
          ddlCity.DataBind();
      }
  
      private void BindGridView(string field)
      {
  
  
          DataTable dt = new DataTable();
          string constring = ConfigurationManager.ConnectionStrings["AccreString"].ConnectionString;
          SqlConnection conn = new SqlConnection(constring);
  
          try
          {
              conn.Open();
              SqlCommand comm = new SqlCommand("SELECT * FROM emed_accredited_providers WHERE DOCTOR_CODE =@pcode", conn);
              comm.Parameters.AddWithValue("@pcode", ddlProvince.SelectedValue);
              SqlDataAdapter adptr = new SqlDataAdapter(comm);
              adptr.Fill(dt);
  
              SqlParameter param = new SqlParameter();
              param.ParameterName = "@pcode";
              param.Value = ddlProvince;
  
              comm.Parameters.Add(param);
  
              if (dt.Rows.Count &gt; 0)
              {
                  GridView1.DataSource = dt;
                  GridView1.DataBind();
              }
              else
              {
              }
              // NO RECORDS FOUND 
          }
          catch (System.Data.SqlClient.SqlException ex)
          {
              string msg = "Fetch Error:";
  
              msg += ex.Message;
              throw new Exception(msg);
          }
          finally
          {
              conn.Close();
          }
      }
  
  
      protected void btnSearch_Click(object sender, EventArgs e)
      {
          BindGridView(txtName.Text.Trim());
      } 
  }
  </code></pre>
  
  <p>I'm new to this, please assist me. Thanks!</p>