0

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.

1
Contributor
1
Reply
4
Views
4 Years
Discussion Span
Last Post by MaddTechwf
0

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
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.