title: C# Populate Gridview from Dropdown choice
body: <p>I have tried everything but can not figure out how to populate a gridview with my dropdown selection.  I have checked the value of the dropdown and it is correct and the gridview will display all items but not the items that I want.  I am using a web form.  Below is my code.</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
          {
              Populate();
          }
  
          protected void btnDisplay_Click(object sender, EventArgs e)
          {
              SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString);
              myConnection.Open();
  
              try
              {
                  SqlDataReader reader = null;
                  string serverIP = drpChoose.SelectedItem.Value.ToString();
                  SqlCommand cmd = new SqlCommand("SELECT * from ScheduledTasks WHERE ServerIP = " + serverIP, myConnection);
  
                  reader = cmd.ExecuteReader();
  
                  while (reader.Read())
                  {
                      GridView1.DataSource = reader;
                      GridView1.DataBind();
                  }
              }
  
              catch (Exception ex)
              {
                  Console.WriteLine(ex.ToString());
              }
  
              myConnection.Close();
          }
  
          public void Populate()
          {
              SqlConnection myConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString);
              myConnection1.Open();
  
              SqlCommand cmd1 = new SqlCommand("SELECT ServerIP FROM Servers", myConnection1);
              SqlDataReader dropReader;
              dropReader = cmd1.ExecuteReader();
  
              drpChoose.DataSource = dropReader;
              drpChoose.DataTextField = "ServerIP";
              drpChoose.DataValueField = "ServerIP";
              drpChoose.DataBind();
          }
      }
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>