Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Need help selecting items from a list box trigger by what selected in dropdown list

Reply
Thread Tools

Need help selecting items from a list box trigger by what selected in dropdown list

 
 
mldardy mldardy is offline
Junior Member
Join Date: Dec 2008
Posts: 5
 
      12-09-2008
Let me preface this by saying I hope someone understands what i am trying to do here. I would really appreciated someones help.

I am trying to send an email(Auto email function) using items in a list box. You can select one or more items to send. The problem I am having is it keeps selecting the first item in the list box instead of what I selected(which could be more than one item). I am setting this equal to a variable called cities where. How do I get this to work to show the items I selected on the To = "" & cities where & "" line. Here is my code for the email:

Code:
Function AutoEmail()
        Dim objMailMessage As MailMessage
        Dim strHtmlBody As String
        conn = New SqlClient.SqlConnection(strconn)
        conn.Open()
        Dim currentAll As String
        Dim strSQL = "SELECT    d.group_descr,  a.first_name, a.last_name, a.user_id, b.email, d.group_id, d.parent_group_id FROM icc_user_data AS a LEFT OUTER JOIN icc_users AS b ON a.user_id = b.user_id LEFT OUTER JOIN icc_users_groups AS c ON a.user_id = c.user_id LEFT OUTER JOIN icc_groups AS d ON c.group_id = d.group_id WHERE      (b.user_id NOT IN (249)) AND (d.group_id IS NOT NULL) AND (d.group_id <> '8') AND (d.group_id <> '10') AND (d.group_id <> '46') AND (d.group_id <> '3') AND (d.group_id <> '47') AND (d.group_id <> '9') ORDER BY d.group_descr"
        Dim Com As New System.Data.SqlClient.SqlCommand(strSQL, conn)
        Dim rdr As System.Data.SqlClient.SqlDataReader = Com.ExecuteReader()
        Dim citiesWhere As String
        citiesWhere = String.Empty
        Dim Item As ListItem
        For Each Item In LBSendTo.Items
            If (Item.Selected) Then
                citiesWhere += "" & Item.Text + ";"
            End If
        Next
        objMailMessage = New MailMessage
       
        objMailMessage.To = "" & citiesWhere & ""
        strHtmlBody = "<TABLE>"
       
        strHtmlBody = strHtmlBody & "</TABLE>"
        objMailMessage.Body = strHtmlBody
        objMailMessage.BodyFormat = MailFormat.Html
       
        SmtpMail.Send(objMailMessage)
    End Function
Code for the Dropdown list selected change:

Code:
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

conn = New SqlClient.SqlConnection(strconn)

conn.Open()

Dim strSQL = "SELECT d.group_descr, a.first_name, a.last_name, a.user_id, b.email, d.group_id, d.parent_group_id FROM icc_user_data AS a LEFT OUTER JOIN icc_users AS b ON a.user_id = b.user_id LEFT OUTER JOIN icc_users_groups AS c ON a.user_id = c.user_id LEFT OUTER JOIN icc_groups AS d ON c.group_id = d.group_id WHERE (b.user_id NOT IN (249)) AND (d.group_id IS NOT NULL) AND (d.group_id <> '8') AND (d.group_id <> '10') AND (d.group_id <> '46') AND (d.group_id <> '3') AND (d.group_id <> '47') AND (d.group_id <> '9') and d.group_id = '" & Me.DropDownList1.SelectedValue & "' ORDER BY d.group_descr"

Dim Com As New System.Data.SqlClient.SqlCommand(strSQL, conn)

Dim rdr As System.Data.SqlClient.SqlDataReader = Com.ExecuteReader

rdr.Read()

Me.DropDownList1.SelectedValue = rdr.Item(5).ToString

fillMonthlyDownloadsListBox()

LoadMonthlyDownloadsGrid()

End Sub
When I click on the send button it put the first item list in the listbox in the to: email. When it should put what I select as the to: email.

For example, the listbox will have let's say 4 names and email addresses:

John(john's email address)
Marc(marc's email address)
Bill(bill's email address)
Steve(steve's email address)

I select Bill or Bill and Steve but instead of selecting Bill or Bill and Steve's email address it will select John's email address to send to when I didn't select John in the list box when i go through the for/next loop because it is the first item listed.



BTW I do have the list box set for multiple selection.

I know this is a lot to absorb but I felt I needed to include as much as I can so someone could understand what was going on.
 
Reply With Quote
 
 
 
 
mldardy mldardy is offline
Junior Member
Join Date: Dec 2008
Posts: 5
 
      12-10-2008
Bumping this up to see if anyone has any ideas on this.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
populate one list box with selected values from another list box steven.cooper@infocision.com ASP .Net 1 03-12-2005 11:29 PM
help with selecting items in a list box newcomer Javascript 1 11-24-2004 08:50 PM
Re: need selected value from dropdown list box Scott Allen ASP .Net 1 08-25-2004 07:09 PM
Dropdown list cannot have multiple items selected! Jeff Tolman ASP .Net 1 01-07-2004 03:36 PM
Selecting items in a list box Mark Javascript 0 10-31-2003 07:41 AM



Advertisments