Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Convert selectedindex value to an email recipient

Convert selectedindex value to an email recipient

Scheduled Pinned Locked Moved Visual Basic
csharpcomhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    archangel717
    wrote on last edited by
    #1

    Hey all, I wrote a simple web form that has a drop down list with various property locations. I need my code to assign a specific email address to a selectedindex value based on the location. For instance: If the user selects Detroit as the location, then the recipient of the mailmessage should be detroit@company.com. Can I do this correctly in an If/Then statement outside of my MailMessage sub? Like : Dim Address As System.Net.Mail.MailAddress If ddlLocation.SelectedIndex = 1 Then Address = "helpdesk@turnberry.com" End If Obviously I need to convert the string somehow, so any help here would be great. Thanks!!

    D 1 Reply Last reply
    0
    • A archangel717

      Hey all, I wrote a simple web form that has a drop down list with various property locations. I need my code to assign a specific email address to a selectedindex value based on the location. For instance: If the user selects Detroit as the location, then the recipient of the mailmessage should be detroit@company.com. Can I do this correctly in an If/Then statement outside of my MailMessage sub? Like : Dim Address As System.Net.Mail.MailAddress If ddlLocation.SelectedIndex = 1 Then Address = "helpdesk@turnberry.com" End If Obviously I need to convert the string somehow, so any help here would be great. Thanks!!

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You could do it that way, or you could just get the data from the SelectedItem in the ComboBox, or from the SelectedValue property if you're using a bound ComboBox, or looking up in a table you have. This really depends on how you filled the ComboBox and from what kind of source and the format of the email address. If it were me, and I'm making a couple of large assumptions here, I'd probably have the Location and email address in a table, bind the combobox to it setting the Location column as the DisplayMember and the email address as the ValueMember, then do something like:

      Dim emailAddr As String = ComboBox.SelectedValue
      

      Or

      Dim emailAddr As String = ComboBox.SelectedValue @ "@someplace.com"
      

      The second way is less flexible though.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      A 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You could do it that way, or you could just get the data from the SelectedItem in the ComboBox, or from the SelectedValue property if you're using a bound ComboBox, or looking up in a table you have. This really depends on how you filled the ComboBox and from what kind of source and the format of the email address. If it were me, and I'm making a couple of large assumptions here, I'd probably have the Location and email address in a table, bind the combobox to it setting the Location column as the DisplayMember and the email address as the ValueMember, then do something like:

        Dim emailAddr As String = ComboBox.SelectedValue
        

        Or

        Dim emailAddr As String = ComboBox.SelectedValue @ "@someplace.com"
        

        The second way is less flexible though.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        A Offline
        A Offline
        archangel717
        wrote on last edited by
        #3

        As you mentioned using the value, I realized how complicated I was making this. Thanks for your direction. I just added a single line of code in my submit click event and added the emails to the ddl as values and everything works great! Dim Email As New System.Net.Mail.MailMessage( _ "email@email.com", ddlLocation.SelectedValue) Thanks again!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups