PDA

Click to See Complete Forum and Search --> : SelectedItem for a DropDownList, SelectedItem ALWAYS 0


Wokawidget
Jun 15th, 2004, 08:04 AM
Why is this value always 0?
I have searched this forums and haven't found much.
I have this code:

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim objComments As New Comment
With objComments
.Name = txtName.Text
.Email = txtEmail.Text
.TypeID = cboArea.SelectedIndex
.Comment = txtComments.Text
.Update()
End With
End Sub

Where "comments" is a class module that has 4 props and some code to save to the DB. Simple really.

Regardless of what I select in my combo the selectedindex is always 0, which means I can't get the ID value for the selected item.
I have ASP.NET Unleased and it's sample code is exactly what I have above :(

Woka

Ecniv
Jun 15th, 2004, 08:43 AM
Haven't messed around with .Net (it refused to install on my computer...) but the old property was 'listindex', or list(row,column).

listindex was the actual index selected
list allows you to access the columns (such as the hidden one with the value or the text (visible) column.

Vince

Wokawidget
Jun 15th, 2004, 08:46 AM
Hahahaha...:D You have a point, but alas that is VB6. .NET is very different in that aspect. Most of the controls have completely different interfaces and functionality :(
This is what is making it hard for me to learn as I keep trying to code in VB6 and it doesn't recognise the code...Booooooo, bad .NET *slap* :)

When dealing with ASP.NET the controls act funny coz they arn'ty on the client, they are on the server. So you have to do some strange method to "post" the value back...can't seem to work out what it is though :(

Thanks for your answer.

Woodf

Wokawidget
Jun 15th, 2004, 10:15 AM
Fixed it :D
I loaded the values in the Page_Load event, but didn't check if was a post back :( This reset my combo to the 1st entry everytime I click the send button :(
What I have now is:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As DataSet
Dim db As New Database
Dim objRow As DataRow
If Not IsPostBack Then
ds = db.GetDataSet("SELECT * FROM CommentTypes")
With cboArea
.DataSource = ds.Tables(0)
.DataTextField() = "Description"
.DataValueField = "ID"
.DataBind()
End With
End If
End Sub

I know the code can be tidied up a little more. But it works :D

Woof