?
Solved

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

Posted on 2012-08-30
4
Medium Priority
?
509 Views
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
            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.
0
Comment
Question by:runnerjp2005
  • 2
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38349543
Where do you get the error? Which line?
0
 

Author Comment

by:runnerjp2005
ID: 38349549
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 38349658
Its because you have a comma in function call

Change

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

to

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

Expert Comment

by:phytax
ID: 38349707
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

830 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