Link to home
Start Free TrialLog in
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
ASKER CERTIFIED SOLUTION
Avatar of Ron Malmstead
Ron Malmstead
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial