I have a GridView called GridView1. I want to load it based on a ButtonTest being clicked. When the button is clicked, I need to do a SQL retrieval of data and popuplate the GridView with it. I can write the SQL code to get the data but I wasn't sure how to load the data into the GridView1.

On a side note, could anyone tell me how I can leverage the SELECT column to my advantage. I would like to have it read the id of the row it's on and redirect to a new page with a url similar to this UserProfile.aspx?UserID=__ .

Thanks for any help in advance.

I actually solved my own question. I have called the bind to early.

Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
        Dim ds As New DataSet
        Dim str As String = ""

        If SearchTypeDDL.SelectedValue = "First Name" Then
            str = "Select ID, PhotoFileName, Name_First, Name_Last, timestamp FROM tbl_people WHERE Name_First='" & Searchtxtbx.Text & "'"
        ElseIf SearchTypeDDL.SelectedValue = "Last Name" Then
            str = "Select ID, PhotoFileName, Name_First, Name_Last, timestamp FROM tbl_people WHERE Name_Last='" & Searchtxtbx.Text & "'"
        ElseIf SearchTypeDDL.SelectedValue = "Username" Then
            str = "Select ID, PhotoFileName, Name_First, Name_Last, timestamp FROM tbl_people WHERE username='" & Searchtxtbx.Text & "'"
        End If

        Dim con As String = ConfigurationManager.ConnectionStrings("ContactManagerString").ConnectionString

        Dim da As New SqlDataAdapter(str, con)

        da.Fill(ds, "tbl_people")

        ResultsGridView.DataSource = ds.Tables("tbl_people").DefaultView
        ResultsGridView.DataBind()
        ResultsPanel.Visible = True
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.