troubleshooting Question

Question on use of Select with Gridview

Avatar of jjc9809
jjc9809 asked on
ASP.NETVisual Basic.NET
1 Comment1 Solution420 ViewsLast Modified:
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
Ron Malmstead
Network Operations Manager

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros