Check Box Selections--Form Email Trouble

Posted on 2008-11-13
Last Modified: 2012-05-05
I have a form in VB which emails the results.
I am having trouble getting the selections checked in a checkbox to appear in the email.
I don't care how I accomplish this--checkboxes or listboxes with multi selects, but I can't seem to
get it to work.

Here's the checkbox
  <asp:checkboxlist id="ReasonForRequest" runat="server">
      <asp:listitem id="Annexation" runat="server" value="Annexation />
      <asp:listitem id="Consolidation" runat="server" value="Consolidation" />

Here's the coding to create the mail contents.
Everything else--textboxes and drop downs have worked...
  '(1) Create the MailMessage instance
         Dim mm As New MailMessage(UsersEmail.Text, ToAddress)
         mm.CC.Add(new MailAddress(UsersEmail.Text))

        Dim sMsg as String
       'example of text box --this works OK
        sMsg+="Last Name : " & lastName.Text & vbcrlf

     ' here I am trying to put the check checkedboxlist items in to a string
       sMsg+="ReasonForRequest : " & ReasonForRequest.Items[0].Text & vbcrlf
       sMsg+="ReasonForRequest : " & ReasonForRequest.Items[1].Text & vbcrlf

This will cause me to get an error
BC30452: Operator '&' is not defined for types 'String' and 'System.Web.UI.WebControls.ListItemCollection'

How can I get the checkbox selections to appear in the mail?
Question by:LT1415
    LVL 13

    Expert Comment

    try that
    sMsg=sMsg & "ReasonForRequest : " & ReasonForRequest.Items[0].Text & vbcrlf
    sMsg=sMsg & "ReasonForRequest : " & ReasonForRequest.Items[1].Text & vbcrlf

    Author Comment

    BC30452: Operator '&' is not defined for types 'String' and 'System.Web.UI.WebControls.ListItemCollection'

    Thanks, but I still am receiving the same error -- it doesn't like the &
    LVL 13

    Expert Comment

    this should do
    sMsg = sMsg & "ReasonForRequest : " & ReasonForRequest.Items(0).Text & vbCrLf
            sMsg = sMsg & "ReasonForRequest : " & ReasonForRequest.Items(1).Text & vbCrLf
    LVL 13

    Accepted Solution

    also remove id=" " runat="server"   from ListItem like below

    <asp:CheckBoxList ID="ReasonForRequest" runat="server">
                <asp:ListItem Value="Annexation">
                <asp:ListItem Value="Consolidation">

    Author Comment

    That worked thanks so much
    LVL 13

    Expert Comment

    u welcome :)

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    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…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    728 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

    15 Experts available now in Live!

    Get 1:1 Help Now