Hi! I need a help!! I'm currently working on an Online Election.

Basically, what i want is to output the list of candidates in every position in my database.
I output the list of the positions in a dynamic labels and the list of candidates in a dynamic dropdownlist.

For the position and candidates, I have the code of it and it works pretty well.

My problem is, I want to get the value of the selectedValue of the dropdownlist. In order for me to have it, i need to have an event handler.

Here is my code for the dynamic dropdownlist..

            sqlCon3.Open()
            sqlSearch3 = "Select candidateName from tblcandidates where positionID=" & lbl(num2).Text & ""
            sqlCmd3 = New SqlCommand(sqlSearch3, sqlCon3)
            sqlDr3 = sqlCmd3.ExecuteReader

            dropdown(num3) = New DropDownList

            While sqlDr3.Read
                dropdown(num3).ID = "dd" & num3.ToString
                dropdown(num3).Items.Add(sqlDr3("candidateName"))
                pnlcandidates.Controls.Add(dropdown(num3))
            End While

            sqlDr3.Close()
            sqlDr3 = Nothing
            sqlSearch3 = Nothing
            sqlCmd3 = Nothing
            sqlCon3.Close()

            Dim spacer As LiteralControl = New LiteralControl("<br /><br />")
            pnlcandidates.Controls.Add(spacer)

for the AddHandler dropdown(num3).selectedIndexChanged, AddressOf DD_indexchanged I know that it is for the event handler BUT when i have this

Protected Sub DD_texchanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim value As String = CType(sender, DropDownList).selectedValue
    lbl1.text = value
End Sub

I can't see the value of the selectedValue of the dropdownlist..

Please Help me.. Thank YOu!

Member Avatar for LastMitch

My problem is, I want to get the value of the selectedValue of the dropdownlist. In order for me to have it, i need to have an event handler.

I assume there's no error with the query?

I can't see the value of the selectedValue of the dropdownlist..

You need to used this code (to get the selectedValue of the dropdownlist):

http://msdn.microsoft.com/en-us/library/system.web.ui.page.ispostback.aspx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.