Solved

Dropdownlist - VB2005

Posted on 2006-07-22
1
283 Views
Last Modified: 2008-03-10
How can I do this. When I select an item on Dropdownlist, I want it to display the item on a textbox. Does it has to postback all the time. I'm using Dropdowlist Task and selected Datasource for SQL database.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click


        Me.TextBox1.Text = Me.DropDownList1.SelectedItem.Text


    End Sub
0
Comment
Question by:VBdotnet2005
1 Comment
 
LVL 9

Accepted Solution

by:
jonorossi earned 125 total points
ID: 17160792
You can use some JavaScript to set the value of the text box with the onchange html select event. Or you could use an AJAX framework like Microsoft Atlas (atlas.asp.net) if you are going to do more than just setting a basic value (eg. getting data from your database).

Here is some javascript that you can use. Take note that ASP.NET changes the names of your controls so you might like to make use of the ClientID property of your controls instead of hardcoding the IDs.

  <script type="text/javascript">
    function setTextBoxValue() {
      var ddl = document.getElementById("ddlTest");
      document.getElementById("txtTest").value = ddl.options[ddl.selectedIndex].value;
    }
  </script>
 
  <select id="ddlTest" onchange="javascript:setTextBoxValue();">
    <option>hey</option>
    <option>bye</option>
  </select>
 
  <input id="txtTest" type="text" />
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now