|
-
Apr 11th, 2003, 10:58 PM
#1
Thread Starter
New Member
Getting the selection from dropdownlist
I'm trying to get the value of the selection from the databound dropdownlist to be displayed in a textbox. Please help.
I have set the Autopostback property to true.
However, the value that is displayed in the textbox 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
-
Apr 12th, 2003, 09:49 AM
#2
Frenzied Member
Check for page postback in the sub load routine
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If ( Not IsPostBack)
OleDbDataAdapter1.Fill(DataSet11)
DropDownList1.DataBind()
EndIf
End Sub
Dont gain the world and lose your soul
-
Apr 12th, 2003, 11:49 PM
#3
PowerPoster
To expand further on that, the reason you are always getting the first value is because the page load event happens before other events are processed. Which means that you are reloading the combo box with values from the database and the selected index gets changed before the selectedindex event gets to process. So when the event actually fires, you will always get the first one.
Now, if you wrap code in a if statement that checks to see if the page is being posted back, then you can prevent the combobox resetting the data in itself when the page is posted back. Hence the reason DevGrp posted what he did.
-
Apr 13th, 2003, 09:48 PM
#4
Thread Starter
New Member
It's working! Thanx so much!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|