?
Solved

Check Box List ASP.NET SQL

Posted on 2014-10-09
3
Medium Priority
?
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

801 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