Solved

Dropdownlist - VB2005

Posted on 2006-07-22
1
284 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 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

15 Experts available now in Live!

Get 1:1 Help Now