0

My current problem is that I have set up a list view on aspx page which displays the emails on a selecting sql statement. I want to be able to take the email value (multiple listed) and insert them into .cs email function (specifically the toEmail string. The two problems I have would be im not sure how to take a value out of list view, and im not sure how to implement a for loop to insert more than one value to be assigned to toEmail.

Appreciate the help, many thanks

.cs code

MailMessage message = new System.Net.Mail.MailMessage();
string fromEmail = lectureremail.Text;
string fromPW = userpassword;

// want toEmail value be selected from listview (which will contain multiple values)

string toEmail =;


message.From = new MailAddress(fromEmail);
message.To.Add(toEmail);
message.Subject = txtSubject.Text;
message.Body = txtBody.Text;
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

using (SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587))
{
    smtpClient.EnableSsl = true;
    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtpClient.UseDefaultCredentials = false;
    smtpClient.Credentials = new NetworkCredential(fromEmail, fromPW);
    smtpClient.Send(message.From.ToString(), message.To.ToString(),
                        message.Subject, message.Body);
}

List view information on .aspx:

<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource2" GroupItemCount="3"
asp:Label ID="emailLabel" runat="server" Text='<%# Eval("email") %>' />
<br />
</td>
</AlternatingItemTemplate>
 /asp:ListView>
MrFeat60
  • 1
  • 1
  • You have not asked a question in your post, and you have posted clearly invalid ASPX markup. Please cleanup your question to correct these problems. – mason Nov 28 '15 at 17:15
  • Here's various ways to get multiselect Listbox items (http://stackoverflow.com/a/1586100/3585500). And then `if (item.selected) { toEmail += item + ";"; }` (even though appending strings in a loop is [frowned upon](https://msdn.microsoft.com/en-us/library/ms182272(v=vs.80).aspx). – ourmandave Nov 28 '15 at 17:56
  • @ourmandave inferred that what you really wanted to use was a _ListBox_, not a _ListView_, in order to allow a user to select one item (you can use the _SelectedValue_ property) or multiple items (you can iterate through its _Items_ collection and test the _Selected_ property). – user2638401 Nov 28 '15 at 18:04

0 Answers0