473,385 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

MailMessage with CheckBoxList Values

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.

Jul 27 '06 #1
3 3754
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

Sully wrote:
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.
Jul 28 '06 #2
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.

Jul 28 '06 #3
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[i].Selected )
{
s = s + Check1.Items[i].Text + "<br>";
}
}

Sincerely,
simida

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.
Jul 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: CJ | last post by:
I generate my checkboxlist from a table(Category) in database. The checked values i save in a table call CategoryID. My problem is that i can't get the checked values from the web form. AND...
0
by: Agi Chen | last post by:
Hello, theres, I'm newbie in asp.net. I have problem in CheckBoxList binding to database. Considering my case in a member system, if I have 2 tables one for interest, one for memberInterest the...
1
by: Tom | last post by:
Hi, I have a webform which has DropDownList, RadioButtonList and CheckBoxList. All values are in webform, but not select from DB table as they do not need to be used as search requirements. ...
3
by: Jack Black | last post by:
Using VS.Net 2k3 to build ASP.Net app with VB code-behind pages... Hi, all! I've been struggling with getting a dynamically-generated CheckBoxList generated. I've finally been able to get the...
2
by: Patrick.O.Ige | last post by:
I have some boolean value(1 or 0 ) in a table and i want a databinded CheckBoxList to present the selected values on the page.. With CheckBox i know i can se the Checked property like so :-...
2
by: Patrick.O.Ige | last post by:
I have a Checkboxlist that is databinded and i want to pass it a boolean value from a table because i want to display the checked values if its TRUE. When Databinding my checkboxlist i'm not...
0
by: Nam | last post by:
I want to use the same sqlDataSource for two CheckBoxList controls in ASP.NET 2.0. For simplicity, I am using the case of only two CheckBoxList controls in the following example: My...
0
by: avital | last post by:
Hi, Hope someone can please help. I have a Gridview with a checkboxlist. On edititemTemplate I want the checkboxlist items to be selected as returned from the database. In the database I...
1
by: terminul | last post by:
Hi I have a datalist which loops through the categories and within the datalist I have a CheckBoxList which are bound on the DataList's OnItemDataBound. The only problem I have is retrieving...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.