Dropdown menu error - Conversion from string "chinaad" to type 'Integer' is not valid.

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Populate1()
        End If
    End Sub

    Public Sub Populate1()
        Using con As New SqlConnection(local)
            Dim cmd As New SqlCommand("SELECT * FROM IntranetUsers", con)
            cmd.Connection.Open()

            Dim ddlValues As SqlDataReader
            ddlValues = cmd.ExecuteReader()

            agents.DataSource = ddlValues
            agents.DataValueField = "Username"
            agents.DataTextField = "Username"
            agents.DataBind()

            cmd.Connection.Close()
            cmd.Connection.Dispose()
        End Using
    End Sub


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox(dayselect.Text, agents.SelectedValue)
    End Sub

Open in new window

Agent: <asp:DropDownList ID="agents" runat="server"> </asp:DropDownList>
       Date:<asp:TextBox ID="dayselect" runat="server"></asp:TextBox>
     <asp:CalendarExtender Format="d/MM/yyyy" ID="CalendarExtender1" runat="server" TargetControlID="dayselect">
    </asp:CalendarExtender>
    <asp:Button ID="Button1" runat="server" Text="Button" />

Open in new window


Hello I cannot figure out why i get the error"" is there any reason I cannot select the selected value.
runnerjp2005Asked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
Its because you have a comma in function call

Change

MsgBox(dayselect.Text, agents.SelectedItem.Text)

to

MsgBox(dayselect.Text & ", " & agents.SelectedItem.Text)
0
 
CodeCruiserCommented:
Where do you get the error? Which line?
0
 
runnerjp2005Author Commented:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox(dayselect.Text, agents.SelectedItem.Text)
    End Sub

when trying to show the selected item
0
 
phytaxCommented:
Hi,

your using

Public Function MsgBox( _
   ByVal Prompt As Object, _
   Optional ByVal Buttons As MsgBoxStyle = MsgBoxStyle.OKOnly, _
   Optional ByVal Title As Object = Nothing _
) As MsgBoxResult

The second option is an Integer an describes the Buttons to show.

Maybe this is for you
Dim message = String.Format("Day selected: {0}{1}Item selected: {2}", dayselect.Text, vbNewLine, agents.SelectedItem.Text)
MsgBox(message)

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.