Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Thread: GridView isn't showing up

Thread: GridView isn't showing up

Scheduled Pinned Locked Moved ASP.NET
csshelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Albert83
    wrote on last edited by
    #1

    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:

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups