Solved

Check Box List ASP.NET SQL

Posted on 2014-10-09
3
202 Views
Last Modified: 2014-10-14
I am working on a program that has a checkboxlist control.

What I am building is a type of messaging program.

The controlbox contains names from a db that also has emails attached to that name.

I want it so if the user selects multiple items that it pulls the emails from the checkbox list

I was thinking in may need to be something like foreach (listitems li in checkboxlist.items)
select from table.

I am not quite sure how to do this.

It has to construct an email and add all selected recipients to the email. Not a new email each time.
0
Comment
Question by:desiredforsome
  • 2
3 Comments
 
LVL 8

Expert Comment

by:johny_bravo1
ID: 40371148
Bind Email as ValueField of CheckboxList
  string items = string.Empty;
    foreach (ListItem i in chkUsers.Items)
    {
        if (i.Selected == true)
        {
            items += i.Value + ",";
        }
    }

Then you will have all the selected users' email addresses in "items" which you can use to send email
0
 

Accepted Solution

by:
desiredforsome earned 0 total points
ID: 40371310
I figured it out.

I used the IN for the select statement

 foreach (System.Web.UI.WebControls.ListItem item in CheckBoxList1.Items)
        {
            if (item.Selected)
            {
                // If the item is selected, add the value to the list.
                YrStrList.Add(item.Value);
            }
            else
            {
                // Item is not selected, do something else.
            }
        }
        
        String YrStr = String.Join("','", YrStrList.ToArray());

        string startquery = String.Concat("SELECT EMAILADDRESS FROM OUTLOOKREPORT.DBO.MFDIRECTORY WHERE name IN('", YrStr);
        
        selectemailquery = string.Concat(startquery, "')");
        List<String> emailfind = new List<string>();
        SqlCommand cmd = con.CreateCommand();
        cmd.CommandText = selectemailquery;
        

        con.Open();
        SqlDataReader reader1 = cmd.ExecuteReader();
        while (reader1.Read())
        {
          
            emailfind.Add(reader1[0].ToString());

        }
        multiemail = string.Concat("\"",string.Join(",", emailfind.ToArray()), "\"");

Open in new window

0
 

Author Closing Comment

by:desiredforsome
ID: 40379422
I figured it out
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), 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, f…

911 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

22 Experts available now in Live!

Get 1:1 Help Now