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

Posted on 2012-08-30
Last Modified: 2012-08-30
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
        End If
    End Sub

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

            Dim ddlValues As SqlDataReader
            ddlValues = cmd.ExecuteReader()

            agents.DataSource = ddlValues
            agents.DataValueField = "Username"
            agents.DataTextField = "Username"

        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: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.
Question by:runnerjp2005
    LVL 83

    Expert Comment

    Where do you get the error? Which line?

    Author Comment

    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
    LVL 83

    Accepted Solution

    Its because you have a comma in function call


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


    MsgBox(dayselect.Text & ", " & agents.SelectedItem.Text)
    LVL 1

    Expert Comment


    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)

    Open in new window


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now