Solved

Check Box List ASP.NET SQL

Posted on 2014-10-09
3
203 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

803 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