MailMessage with CheckBoxList Values

S

Sully

Hi,
I am having a small problem generating an e-mail via an online form. I
am creating an e-mail using the MailMessage command and I know that you
have to do something special to render the values Checked with a
CheckBoxList, but I don't know what to do or how to do it. If anyone
could give me an example or send me to a link I would appreciate it.

Thanks in advance.
 
S

simida

You can render mail content with html element.such as,

<form method="POST" action="url">
<input type="hidden" name="topic" value="">
<font class=s10>Question?
<br><input type="radio" name="choice" value="0">answer1
<br><input type="radio" name="choice" value="1">answer2
<br><input type="radio" name="choice" value="2">answer3
<br><center><input type="submit" value="vote"></center>
</font></form>

Sincerely,
simida
 
S

Sully

Sorry, I don't think your suggestion is quite what I am looking for, or
maybe I just don't understand. This is my code so far:

<%@ Page Language="C#" AutoEventWireup="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<%@ Import Namespace="System.Web.Mail" %>
<script runat="server">
private void SubmitForm(object sender, System.EventArgs e)
{
// create mail message object
MailMessage Message = new MailMessage();
// set some properties
Message.BodyFormat = MailFormat.Text;
Message.Priority = MailPriority.High;
// create the e-mail
Message.From = "(email omited)";
Message.To = "(email omited)";
Message.Subject = "Online Fleet Quote";
Message.Body = "Contact Information" +
"\nFirst Name:" +txtFirstName.Text +
"\nLast Name:" +txtLastName.Text +
"\nCompany:" +txtCompany.Text +
"\nAddress:" +txtAddress.Text +
"\nCity:" +txtCity.Text +
"\nState:" +ddlStates.SelectedValue +
"\nZip Code:" +txtZipCode.Text +
"\nCountry:" +ddlCountry.SelectedValue +
"\n" +
SmtpMail.Send(Message);
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
</head>
<body>
<form runat="server"
<table width="480" border="0" align="center" cellpadding="0"
cellspacing="0" class="Fleet_Services_Text">
<tr>
<td colspan="4"><b>Contact Information</b></td>
</tr>
<tr>
<td><img src="../images/fleet/spacer.gif" alt="spacer"
width="80" height="1"/></td>
<td><img src="../images/fleet/spacer.gif" alt="spacer"
width="160" height="1"/></td>
<td><img src="../images/fleet/spacer.gif" alt="spacer"
width="80" height="1"/></td>
<td><img src="../images/fleet/spacer.gif" alt="spacer"
width="160" height="1"/></td>
</tr>
<tr>
<td width="80" class="oq_QuestionPadding">First
Name:</td>
<td width="160"><asp:TextBox ID="txtFirstName"
runat="server" Width="125" Style="width:125px;"
CssClass="oq_TextBox"></asp:TextBox></td>
<td width="80" class="oq_QuestionPadding">Last Name:
</td>
<td width="160"><asp:TextBox ID="txtLastName"
runat="server" Width="150" Style="width:150px;"
CssClass="oq_TextBox"></asp:TextBox></td>
</tr>
<tr>
<td class="oq_QuestionPadding">Company:</td>
<td colspan="3"><asp:TextBox ID="txtCompany"
runat="server" Width="390" Style="width:390px;"
CssClass="oq_TextBox"></asp:TextBox></td>
</tr>
<tr>
<td class="oq_QuestionPadding">Address:</td>
<td colspan="3"><asp:TextBox ID="txtAddress"
runat="server" Width="390" Style="width:390px;"
CssClass="oq_TextBox"></asp:TextBox></td>
</tr>

<tr>
<td class="oq_QuestionPadding">City:</td>
<td><asp:TextBox runat="server" ID="txtCity" Width="125"
Style="width:125px;" CssClass="oq_TextBox"></asp:TextBox></td>
<td class="oq_QuestionPadding">State:</td>
<td>
<asp:DropDownList ID="ddlStates" runat="server"
CssClass="oq_TextBox" AutoPostBack="false"></asp:DropDownList>
</td>
</tr>
<tr>
<td class="oq_QuestionPadding">Zip Code: </td>
<td><asp:TextBox ID="txtZipCode" runat="server"
Width="125" Style="width:125px;"
CssClass="oq_TextBox"></asp:TextBox></td>
<td class="oq_QuestionPadding">Country:</td>
<td><asp:DropDownList ID="ddlCountry" runat="server"
CssClass="oq_TextBox">
<asp:ListItem Value="" Text="Select Country"></asp:ListItem>
<asp:ListItem Value="United States" Text="United
States"></asp:ListItem>
<asp:ListItem Value="Canada" Text="Canada"></asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td class="oq_QuestionPadding">Phone:</td>
<td><asp:TextBox ID="txtPhone" runat="server" Width="125"
Style="width:125px;" CssClass="oq_TextBox"></asp:TextBox></td>
<td class="oq_QuestionPadding">e-mail:</td>
<td><asp:TextBox ID="txtemail" runat="server" Width="150"
Style="width:150px;" CssClass="oq_TextBox"></asp:TextBox></td>
</tr>
<tr>
<td class="oq_QuestionPadding" valign="top">Optimal
Service: </td>
<td colspan="3" class="oq_rblPadding">
<asp:CheckBoxList ID="cblServices" runat="server"
CssClass="oq_TextBox" RepeatColumns="2" Width="380"
Style="width:380px;" RepeatDirection="Horizontal">
<asp:ListItem Text="Descriptive Brochures" Value="Descriptive
Brochures"></asp:ListItem>
<asp:ListItem Text="R &amp; D Feedback" Value="R &amp; D
Feedback"></asp:ListItem>
<asp:ListItem Text="Multiple Billing Options" Value="Multiple
Billing Options"></asp:ListItem>
<asp:ListItem Text="Technical Assistance" Value="Technical
Assistance"></asp:ListItem>
<asp:ListItem Text="Sales Call Assistance" Value="Sales Call
Assistance"></asp:ListItem>
<asp:ListItem Text="R &amp; R" Value="R &amp; R"></asp:ListItem>
<asp:ListItem Text="Extended Warranty" Value="Extended
Warranty"></asp:ListItem>
</asp:CheckBoxList>
</td>
</tr>
<tr>
<td class="oq_QuestionPadding">&nbsp;</td>
<td>&nbsp;</td>
<td class="oq_QuestionPadding">&nbsp;</td>
<td style="padding-top:8px;
padding-left:90px;"><asp:Button ID="btnSubmit" runat="server"
Text="Submit" CssClass="oq_TextBox"
OnClick="SubmitForm"></asp:Button></td>
</tr>

</table>
</form>
</body>
</html>

I can't figure out how to include values for the CheckboxList in the
generated e-mail. I tried +cblServices.SelectedValue+ but it only
returns that first value selected and not all of them. If anyone can
help me out here I would appreciate it.

Thanks.
 
S

simida

en.. check CheckboxList Items property, you will get all values.

May be like this?

for (int i=0; i < Check1.Items.Count; i++)
{
if ( Check1.Items.Selected )
{
s = s + Check1.Items.Text + "<br>";
}
}

Sincerely,
simida

Sully 写é“:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top