SQL Database 2005 | ASP.NET
Purpose of my project:
A webform that a user completes that emails people in a database based on which checkboxes(categories) they select.
MY IDEA.....
Webform:
A. Usual contact stuff
B. Description Box which will become the email body
C. CheckboxList which will contain about 40 checkboxes. This list is dynamically generated by binding to a categories table in the database. The contact records in the database are aleady relationally associated to the categories.
D. Submit Button
MY Problem...
How would I iterate through the list and then compare the checkboxes to the database in order to generate the emails to be sent out? If I did this with single check boxes, I could just do a bunch of if statements like if (CheckBox1.Checked) then call a stored procedure that grabs every email address that is associated with checkbox1. I don't know how to do this with a list.
How would some of you pros tackle this ?
Wouldn't it just be something like..
foreach (ListItem itemin CheckBoxList1.Items)
{
if (item.Selected)
{
// Send email
}
}
That will get me a list of what is selected. but then how do I compare the list against the database. Here is what I was using before with just single checkboxes:
protected void btnSubmit_Click(object sender, System.EventArgs e)
{
if (CheckBox1.Checked)
{
PassID("1");
}
if (CheckBox2.Checked)
{
PassID("2");
}
etc...etc..etc..
PassID method calls a stored proceedure that passes in the value of the checkbox and returns all the records associated with it.
IE.
PassID get all the emails that are assocaited with checkbox 1 and put them in a collection
I'm not sure how to get this to work with a checkboxlist, I'm not even sure you can do it this way.
Why wouldn't this work (assuming PassID returns a collection of Email objects)?
List<Email> emailCollection =new List<Email>();foreach (ListItem itemin CheckBoxList1.Items)
{
foreach (Email emailin PassID(item.Value))
emailCollection.Add(email);
}
Hmm...
I didn't even think of that. I'm going to monkey around with that though. I think that is exactly the direction I need to go.
Thanks for the help Justin!!
JustinHolton:
Why wouldn't this work (assuming PassID returns a collection of Email objects)?
List<Email> emailCollection =new List<Email>();foreach (ListItem itemin CheckBoxList1.Items)
{
foreach (Email emailin PassID(item.Value))
emailCollection.Add(email);
}
List<Email> emailCollection =new List<Email>();
How are you getting Email as a type? What does that derive from?
It would be a custom type in your BLL, i.e. a class you wrote. It's just an example I used for clarity. Unless you're doing anything special with email addresses feel free to use a string instead.
Thanks again bro. I'm still learning c# and the framework I looked all over for information on an email data type. LOL
0 comments:
Post a Comment