Avatar of jjc9809
jjc9809
 asked on

Question on use of Select with Gridview

Hi Everyone,

I have a Gridview that I am loading based on the Driver License Number that is selected with a drop down list.  I want to have a Select on the gridview which will allow the user to move data from each field in the gridview to textboxes defined on the web form.

i have seen this done by using a Reader in VB Coding, but I do not know how to do this with the coding I have already done.

Please see my coding below which loads my gridview with the data that pertains to the License Number, but I want to allow the user to select the row and load a web form with the data into web form textbox controls whihc I have defined.

Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load



        If Page.IsPostBack = False Then

            'Create the SQL Connection and connect to the Enforcement Intelligence Database

            Dim myConnection = New SqlConnection(clsDAL.EnforcementIntelligenceConnection())


            'Create the Query to Execute which pulls data from the Player database with a Select Statement.

            Dim strQuery As String = "Select ID, FK_DriverLicenseID_vch, ContactMonth_ch, ContactDay_ch, ContactYear_ch, ContactAgent_vch FROM Contact_tbl ORDER BY FK_DriverLicenseID_vch"

            ' Create the Comnmand

            Dim myCommand As New SqlCommand(strQuery, myConnection)

            'Open the Sql Connection
            myConnection.open()


            'Show the data in a gridview

            DdlManufacturer.DataSource = myCommand.ExecuteReader()
            DdlManufacturer.DataTextField = "FK_DriverLicenseID_vch"
            DdlManufacturer.DataValueField = "ID"
            DdlManufacturer.DataBind()

            'Always close the SQL Connection when finished.

            myConnection.close()

            'Force the first data bind

            'DdlManufacturer_SelectedIndexChanged(DBNull.Value, DBNull.Value)


        End If
    End Sub

    Protected Sub DdlManufacturer_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DdlManufacturer.SelectedIndexChanged

        'Create the Sql Connection
        Dim myConnection = New SqlConnection(clsDAL.EnforcementIntelligenceConnection())
       

        'Create and Build the Parameter Query that will pull the data based on what is selected with the
        'Drop Down List.

        Dim strQuery As String = "Select ID, FK_DriverLicenseID_vch, ContactMonth_ch, ContactDay_ch, ContactYear_ch, ContactAgent_vch FROM Contact_tbl WHERE @ID = 0 OR ID = @ID"

        'Create the Command Object

        Dim myCommand As New SqlCommand(strQuery, myConnection)

        'Add the Parameter

        Dim myParameter As SqlParameter = New SqlParameter()
        myParameter.ParameterName = "@ID"
        myParameter.SqlDbType = SqlDbType.Int
        myParameter.Value = DdlManufacturer.SelectedValue
        myCommand.Parameters.Add(myParameter)




        'Open the Sql Connection

        myConnection.Open()

        'Show the Data in the Gridview called GVPOI


        GVPOI.DataSource = myCommand.ExecuteReader()
        GVPOI.DataBind()


        'Close the Sql Connection when finished

        myConnection.Close()


    End Sub

    Protected Sub DdlManufacturer_DataBound(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DdlManufacturer.DataBound
        DdlManufacturer.Items.Insert(0, New ListItem("-- AllLicenseNumbers --", "0"))
    End Sub


   
End Class
Visual Basic.NETASP.NET

Avatar of undefined
Last Comment
Ron Malmstead

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ron Malmstead

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.
fblack61