Thread: GridView isn't showing up
-
I am trying to bind a grid in when the user click on a button. What should happen in the button is this: I have to txt boxes - last name, first name. When the user clicks on the button, it should look up the last name entered in the txt box, retrieve the records if there are, and bind to the grid view. However, the results are not showing in grid at all. I created a test label which does show the values entered in the boxes. Here is the code. Thanks for reading and help. cs code: protected void btnFind_Click(object sender, EventArgs e) { string firstName = (string)txtFirstName.Text; string lastName = (string)txtLastName.Text; using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM users_info WHERE last_name = @last_name", conn); cmd.Parameters.Add(new SqlParameter("@last_name", lNAme)); SqlDataReader dr = cmd.ExecuteReader(); int rowsRetrieved = 0; while (dr.Read()) { Label1.Text = "The value is " + dr["last_name"] + dr["first_name"]; rowsRetrieved++; } if (rowsRetrieved >= 1) { GridView1.DataSource = dr; GridView1.DataBind(); GridView1.Visible = true; } Console.WriteLine("{0} row(s) retrieved", rowsRetrieved); dr.Close(); conn.Close(); } aspx file: