473,761 Members | 1,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3776
You can render mail content with html element.such as,

<form method="POST" action="url">
<input type="hidden" name="topic" value="">
<font class=s10>Quest ion?
<br><input type="radio" name="choice" value="0">answe r1
<br><input type="radio" name="choice" value="1">answe r2
<br><input type="radio" name="choice" value="2">answe r3
<br><center><in put 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="te xt/html"
ResponseEncodin g="iso-8859-1" %>
<%@ Import Namespace="Syst em.Web.Mail" %>
<script runat="server">
private void SubmitForm(obje ct sender, System.EventArg s e)
{
// create mail message object
MailMessage Message = new MailMessage();
// set some properties
Message.BodyFor mat = MailFormat.Text ;
Message.Priorit y = MailPriority.Hi gh;
// create the e-mail
Message.From = "(email omited)";
Message.To = "(email omited)";
Message.Subject = "Online Fleet Quote";
Message.Body = "Contact Information" +
"\nFirst Name:" +txtFirstName.T ext +
"\nLast Name:" +txtLastName.Te xt +
"\nCompany: " +txtCompany.Tex t +
"\nAddress: " +txtAddress.Tex t +
"\nCity:" +txtCity.Text +
"\nState:" +ddlStates.Sele ctedValue +
"\nZip Code:" +txtZipCode.Tex t +
"\nCountry: " +ddlCountry.Sel ectedValue +
"\n" +
SmtpMail.Send(M essage);
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<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_Se rvices_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_Quest ionPadding">Fir st
Name:</td>
<td width="160"><as p:TextBox ID="txtFirstNam e"
runat="server" Width="125" Style="width:12 5px;"
CssClass="oq_Te xtBox"></asp:TextBox></td>
<td width="80" class="oq_Quest ionPadding">Las t Name:
</td>
<td width="160"><as p:TextBox ID="txtLastName "
runat="server" Width="150" Style="width:15 0px;"
CssClass="oq_Te xtBox"></asp:TextBox></td>
</tr>
<tr>
<td class="oq_Quest ionPadding">Com pany:</td>
<td colspan="3"><as p:TextBox ID="txtCompany "
runat="server" Width="390" Style="width:39 0px;"
CssClass="oq_Te xtBox"></asp:TextBox></td>
</tr>
<tr>
<td class="oq_Quest ionPadding">Add ress:</td>
<td colspan="3"><as p:TextBox ID="txtAddress "
runat="server" Width="390" Style="width:39 0px;"
CssClass="oq_Te xtBox"></asp:TextBox></td>
</tr>

<tr>
<td class="oq_Quest ionPadding">Cit y:</td>
<td><asp:TextBo x runat="server" ID="txtCity" Width="125"
Style="width:12 5px;" CssClass="oq_Te xtBox"></asp:TextBox></td>
<td class="oq_Quest ionPadding">Sta te:</td>
<td>
<asp:DropDownLi st ID="ddlStates" runat="server"
CssClass="oq_Te xtBox" AutoPostBack="f alse"></asp:DropDownLis t>
</td>
</tr>
<tr>
<td class="oq_Quest ionPadding">Zip Code: </td>
<td><asp:TextBo x ID="txtZipCode " runat="server"
Width="125" Style="width:12 5px;"
CssClass="oq_Te xtBox"></asp:TextBox></td>
<td class="oq_Quest ionPadding">Cou ntry:</td>
<td><asp:DropDo wnList ID="ddlCountry " runat="server"
CssClass="oq_Te xtBox">
<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:DropDownLis t></td>
</tr>
<tr>
<td class="oq_Quest ionPadding">Pho ne:</td>
<td><asp:TextBo x ID="txtPhone" runat="server" Width="125"
Style="width:12 5px;" CssClass="oq_Te xtBox"></asp:TextBox></td>
<td class="oq_Quest ionPadding">e-mail:</td>
<td><asp:TextBo x ID="txtemail" runat="server" Width="150"
Style="width:15 0px;" CssClass="oq_Te xtBox"></asp:TextBox></td>
</tr>
<tr>
<td class="oq_Quest ionPadding" valign="top">Op timal
Service: </td>
<td colspan="3" class="oq_rblPa dding">
<asp:CheckBoxLi st ID="cblServices " runat="server"
CssClass="oq_Te xtBox" RepeatColumns=" 2" Width="380"
Style="width:38 0px;" RepeatDirection ="Horizontal ">
<asp:ListItem Text="Descripti ve Brochures" Value="Descript ive
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="Technica l
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:CheckBoxLis t>
</td>
</tr>
<tr>
<td class="oq_Quest ionPadding">&nb sp;</td>
<td>&nbsp;</td>
<td class="oq_Quest ionPadding">&nb sp;</td>
<td style="padding-top:8px;
padding-left:90px;"><as p:Button ID="btnSubmit" runat="server"
Text="Submit" CssClass="oq_Te xtBox"
OnClick="Submit Form"></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.Se lectedValue+ 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.Co unt; 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="te xt/html"
ResponseEncodin g="iso-8859-1" %>
<%@ Import Namespace="Syst em.Web.Mail" %>
<script runat="server">
private void SubmitForm(obje ct sender, System.EventArg s e)
{
// create mail message object
MailMessage Message = new MailMessage();
// set some properties
Message.BodyFor mat = MailFormat.Text ;
Message.Priorit y = MailPriority.Hi gh;
// create the e-mail
Message.From = "(email omited)";
Message.To = "(email omited)";
Message.Subject = "Online Fleet Quote";
Message.Body = "Contact Information" +
"\nFirst Name:" +txtFirstName.T ext +
"\nLast Name:" +txtLastName.Te xt +
"\nCompany: " +txtCompany.Tex t +
"\nAddress: " +txtAddress.Tex t +
"\nCity:" +txtCity.Text +
"\nState:" +ddlStates.Sele ctedValue +
"\nZip Code:" +txtZipCode.Tex t +
"\nCountry: " +ddlCountry.Sel ectedValue +
"\n" +
SmtpMail.Send(M essage);
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<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_Se rvices_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_Quest ionPadding">Fir st
Name:</td>
<td width="160"><as p:TextBox ID="txtFirstNam e"
runat="server" Width="125" Style="width:12 5px;"
CssClass="oq_Te xtBox"></asp:TextBox></td>
<td width="80" class="oq_Quest ionPadding">Las t Name:
</td>
<td width="160"><as p:TextBox ID="txtLastName "
runat="server" Width="150" Style="width:15 0px;"
CssClass="oq_Te xtBox"></asp:TextBox></td>
</tr>
<tr>
<td class="oq_Quest ionPadding">Com pany:</td>
<td colspan="3"><as p:TextBox ID="txtCompany "
runat="server" Width="390" Style="width:39 0px;"
CssClass="oq_Te xtBox"></asp:TextBox></td>
</tr>
<tr>
<td class="oq_Quest ionPadding">Add ress:</td>
<td colspan="3"><as p:TextBox ID="txtAddress "
runat="server" Width="390" Style="width:39 0px;"
CssClass="oq_Te xtBox"></asp:TextBox></td>
</tr>

<tr>
<td class="oq_Quest ionPadding">Cit y:</td>
<td><asp:TextBo x runat="server" ID="txtCity" Width="125"
Style="width:12 5px;" CssClass="oq_Te xtBox"></asp:TextBox></td>
<td class="oq_Quest ionPadding">Sta te:</td>
<td>
<asp:DropDownLi st ID="ddlStates" runat="server"
CssClass="oq_Te xtBox" AutoPostBack="f alse"></asp:DropDownLis t>
</td>
</tr>
<tr>
<td class="oq_Quest ionPadding">Zip Code: </td>
<td><asp:TextBo x ID="txtZipCode " runat="server"
Width="125" Style="width:12 5px;"
CssClass="oq_Te xtBox"></asp:TextBox></td>
<td class="oq_Quest ionPadding">Cou ntry:</td>
<td><asp:DropDo wnList ID="ddlCountry " runat="server"
CssClass="oq_Te xtBox">
<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:DropDownLis t></td>
</tr>
<tr>
<td class="oq_Quest ionPadding">Pho ne:</td>
<td><asp:TextBo x ID="txtPhone" runat="server" Width="125"
Style="width:12 5px;" CssClass="oq_Te xtBox"></asp:TextBox></td>
<td class="oq_Quest ionPadding">e-mail:</td>
<td><asp:TextBo x ID="txtemail" runat="server" Width="150"
Style="width:15 0px;" CssClass="oq_Te xtBox"></asp:TextBox></td>
</tr>
<tr>
<td class="oq_Quest ionPadding" valign="top">Op timal
Service: </td>
<td colspan="3" class="oq_rblPa dding">
<asp:CheckBoxLi st ID="cblServices " runat="server"
CssClass="oq_Te xtBox" RepeatColumns=" 2" Width="380"
Style="width:38 0px;" RepeatDirection ="Horizontal ">
<asp:ListItem Text="Descripti ve Brochures" Value="Descript ive
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="Technica l
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:CheckBoxLis t>
</td>
</tr>
<tr>
<td class="oq_Quest ionPadding">&nb sp;</td>
<td>&nbsp;</td>
<td class="oq_Quest ionPadding">&nb sp;</td>
<td style="padding-top:8px;
padding-left:90px;"><as p:Button ID="btnSubmit" runat="server"
Text="Submit" CssClass="oq_Te xtBox"
OnClick="Submit Form"></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.Se lectedValue+ 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
1105
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 postback don't work and should not. Here is my code: for(int i=0; i<CheckBoxList1.Items.Count;i++) { if (CheckBoxList1.Items.Selected) //this step will not be true when checked one or more items. { //My code for insert in category table
0
1498
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 SQL DDL like follows: create table interest ( intId int, intName varchar(20)) go Insert into interest values ( 1, 'Music') Insert into interest values ( 2, 'Jogging') Insert into interest values ( 3, 'Fishing')
1
5384
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. For DropDownList and RadioButtonList, there is only one item is selected and store in DB table.
3
5773
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 list generated, but now there are two problems I haven't been able to overcome: 1) ASP.Net is munging the checkbox ID/Names of the checkboxes: I give it a name like "myCheckbox" and asp.net is creating the checkboxes with the name...
2
5237
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 :- <asp:CheckBox id="chk" checked=<% Databind.Eval("This returns 1 or 0")%> runat="server"%> Any help how i can do it using CheckBoxList?
2
1323
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 passing the column name with the boolean values to the DataValueField which is the column "checked" but instead i want to loop through the checkboxlist and pass the Boolean values to it like so below But it seems not to work.!!! Any ideas??
0
1793
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 sqlDataSource is bound to a table in my database. The table has four columns, say, col1_ID, col1_value and col2_ID, col2_value. The DataValueField and DataTextField values for CheckBoxList1 are bound to col1_ID and col1_value respectively. And, for...
0
3524
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 have a table called PrescriptionDetails with a field called Weekdays that can store data in the following format: Monday,Tuesday,Thursday,
1
7938
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 the values that have been checked when the user submits the form. This code works as far as presentation goes but I can't seem to retrieve the checked values in the various checkboxlists that have been generated on the datalist's OnItemDataBound ...
0
9377
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.