Print Page | Close Window

Selection from databound dropdownlist

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: General Discussion
Forum Description: General discussion and chat on any topic.
URL: https://forums.webwiz.net/forum_posts.asp?TID=1780
Printed Date: 28 March 2026 at 9:09pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Selection from databound dropdownlist
Posted By: evelin
Subject: Selection from databound dropdownlist
Date Posted: 11 April 2003 at 10:28pm
I'm trying to get the value of the selection from the databound dropdownlist to be displayed in a textbox.
I have set the Autopostback property to true

However, the value that is displayed is always the first value from the database or rather the selected value is always the first value of the dropdownlist.

Here is the VB code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OleDbDataAdapter1.Fill(DataSet11)
DropDownList1.DataBind()

End Sub

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

End Sub

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim str As String

str = DropDownList1.SelectedItem.Text

TextBox4.Text = str

End Sub
End Class

Please Help. Any assistance will be very much appreciated



Replies:
Posted By: Bunce
Date Posted: 11 April 2003 at 10:41pm

 I think its because you are continuously databinding your dropdownlist on *every* page load.

Try changing you pageload event to this:

If not ispostback then
    OleDbDataAdapter1.Fill(DataSet11)
    DropDownList1.DataBind()
End If

Also, we've got a .Net forum you might get a quicker response in.

Cheers,
Andrew



-------------
There have been many, many posts made throughout the world...
This was one of them.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net