1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Display data from database using selected value from combo list.. (ASP)

Discussion in 'C#' started by rambutanmerah, Sep 9, 2009.

  1. #1
    Hi there,

    Does anyone know how to retrieve and display data from database using combo list? What I mean is this..in a form there are a combo list and two textfields..the user need to choose their company using that combo list. Once they have chose their company, the address and the contact number of the company will be displayed in the next two textfields called CAddress and CContact. For example, if the user chose company ABC, how can I display the company ABC address and contact number in those textfields? Need help. Codes examples are much appreciated. Thank you.
     
    rambutanmerah, Sep 9, 2009 IP
  2. Talker

    Talker Notable Member

    Messages:
    2,795
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    210
    #2
    Hi this would be something to do with ASP and JS.

    Populate the combo item 'value' with the results that you want to show in the text boxes. You can seperate them with any character.

    Then write a JS to update the text value of the text boxes using the 'value' of hte selected combo item.

    Hope it helps.. dont have much time to code it for you.. really sorry.
     
    Talker, Sep 15, 2009 IP
  3. islandhopper8

    islandhopper8 Active Member

    Messages:
    100
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    73
    #3
    Make the combo box autopostback when a selection is made a postback will be done and you can put in the section for the post back the code to retreive the information from database.

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged


    Dim myConnectionString As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
    Dim sqlString As String = Nothing
    Dim myConnection As New MySqlConnection(myConnectionString)
    Dim myAdapter As MySqlDataAdapter = New MySqlDataAdapter(sqlString, myConnection)
    Dim DS As DataSet = New DataSet
    myAdapter.SelectCommand.CommandText = "select address,phonenumber from companies where companyid=" & DropDownList1.SelectedValue
    myAdapter.Fill(DS)
    Dim er As String
    If DS.Tables(0).Rows.Count > 0 Then

    Me.TextBox1.Text = DS.Tables(0).Rows(0).Item("address").ToString
    Me.TextBox2.Text = DS.Tables(0).Rows(0).Item("phonenumber").ToString

    End If

    myAdapter.Dispose()
    myConnection.Dispose()
    DS.Dispose()

    End Sub

    This will do the job. If you want you can add an updatepanel so that you dont get a complete refresh of the webpage when you do a post back.
     
    islandhopper8, Sep 24, 2009 IP
  4. zinist

    zinist Banned

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    43
    #4
    hope it will help you
    Step 1:Make Autopostback property of combobox to true..by default it is false
    Step 2:Give connection string
    Step 3:write sqlquery
    select address,phonenumber from comp where cmpid='"+DropDownList1.SelectedValue+"'
    Step 4:Bind the data in textbox
     
    zinist, Jun 27, 2015 IP