Solved

Check Box List ASP.NET SQL

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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

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 …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

687 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