?
Solved

Getting the results  from a dataset populated checkboxlist

Posted on 2005-03-02
8
Medium Priority
?
460 Views
Last Modified: 2008-03-04
Hi

I am trying to create a page whcih does the following using VB.NET:

I want to display a form the results of which are emailed, part of the form contains a checkboxlist, the contents of which are populated from a dataset I have.

I can get the checkboxlist populated with the relevant sections of the dataset, and I can make the form email.  The bit I can't do is get the multiple selections from the checkboxlist in to the email body content!

Thanks!
0
Comment
Question by:lucinda_rhian
[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
  • 5
  • 2
8 Comments
 
LVL 6

Expert Comment

by:mcgants
ID: 13438164
try this:

Dim item As ListItem
For Each item In cbl1.Items
  If item.Selected = True Then
    txt1.Text &= item.Text & " "
  End If
Next

replace item.text with item.value if you just want the value,
replace txt1.text with whatever variable you are using for your body text

hope this helps,
mcg
0
 

Author Comment

by:lucinda_rhian
ID: 13438647
I tried this and it picks up nothing even though some of the check boxes are checked.

Could my problem be related to the fact that my dataset and id of my checkboxlist control are the same?  ie.  I create a dataset and then use the dataset name as the id of my chcklistbox to get the data from in in the checklistbox, then reference the id in the code above to extract the selections.

Thanks
0
 

Author Comment

by:lucinda_rhian
ID: 13438683
<%@ Register TagPrefix="Control1" TagName="Menu" Src="../menu/menu.ascx" %>
<%@ Page Language="VB"%>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web.Mail" %>
<HTML>
<HEAD>
<title>Form Request</title>
<script language="VB" runat="server">
sub Page_Load(sender as Object, e as EventArgs)

Dim connString as String
connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\Inetpub\wwwroot\forms\btforms.mdb;"
   
'Open a connection
Dim objConnection as OleDbConnection
objConnection = New OleDbConnection(connString)
objConnection.Open()
   
'Specify the SQL string
Dim strSQL as String = "SELECT * FROM Forms WHERE AvailableElectronically=false"

'Create a command object
Dim objCommand as OleDbCommand
objCommand = New OleDbCommand(strSQL, objConnection)

'Get a datareader
Dim objDataReader as OleDbDataReader
objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)

'Do the DataBinding
formResults.DataSource = objDataReader
formResults.DataBind()    
   
'Close the datareader/db connection
objDataReader.Close()
end sub
                  
                  Sub btnSendFeedback_Click(sender as Object, e as EventArgs)

                        'Create an instance of the MailMessage class
                        Dim objMM as New MailMessage()

                        'Set the properties - send the email to the person who filled out the
                        'feedback form.
                        objMM.To = "lucinda.marchant@brandontrust.org"
                        objMM.From = txtEmail.Text

                        'Send the email in text format
                        objMM.BodyFormat = MailFormat.Text
                        '(to send HTML format, change MailFormat.Text to MailFormat.Html)

                        'Set the priority - options are High, Low, and Normal
                        objMM.Priority = MailPriority.Normal

                        'Set the subject
                        objMM.Subject = "BT Form Request"

                              Dim item As ListItem
                              Dim txt1 As String
                              For Each item In formResults.Items
                              If item.Selected = True Then
                                    txt1 &= item.Text & " "
                              End If
                              Next

                        'Set the body
                        objMM.Body = txt1

                         
                        'Specify to use the default Smtp Server
                        SmtpMail.SmtpServer = "earth.brandontrust.org"
                         
                        'Now, to send the message, use the Send method of the SmtpMail class
                        SmtpMail.Send(objMM)

                        panelSendEmail.Visible = false
                        panelMailSent.Visible = true
                  End Sub
                  </script>
                  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      </HEAD>
      <body>
            <table cellPadding="0" width="100%" border="0">
                  <tr>
                        <td>&nbsp;</td>
                        <td align="center" width="900">
                              <DIV align="center">
                                    <table cellSpacing="0" cellPadding="0" width="900" align="center" border="0">
                                          <tr>
                                                <td width="95%" bgColor="#ff9900" height="91">
                                                      <div align="left"><IMG height="64" src="../images/atBrandon.gif" width="283">
                                                      </div>
                                                </td>
                                                <td width="5%" bgColor="#ff9900"><IMG height="89" src="../images/orangebglogo.gif" width="200">
                                                </td>
                                          </tr>
                                    </table>
                              </DIV>
                              <DIV align="center">
                                    <table cellSpacing="0" cellPadding="0" width="100%" align="center" bgColor="#0f298f">
                                          <tr>
                                                <td width="100%"><IMG height="4" src="../images/spacer.gif" width="1">
                                                </td>
                                          </tr>
                                    </table>
                              </DIV>
                              <DIV align="center">
                                    <table cellSpacing="0" cellPadding="0" width="100%" align="center" border="0">
                                          <tr>
                                                <td vAlign="top" width="140" bgColor="#ff9900"><CONTROL1:MENU id="Menu1" runat="server"></CONTROL1:MENU></td>
                                                <td vAlign="top">
                                                      <table cellSpacing="12" cellPadding="0" width="100%" border="0">
                                                            <tr>
                                                                  <td width="100%">
                                                                        <div align="left">
                                                                              <h1 align="center">Hard Copy Forms Request</h1>
                                                                              <P>
                                                                                    <asp:panel id="panelSendEmail" runat="server">
                                                                                          <FORM id="Form1" runat="server">
                                                                                                <P>Please request forms not available electronically by filling in the form below:</P>
                                                                                                <P>
                                                                                                      <TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="0">
                                                                                                            <TR>
                                                                                                                  <TD width="147">Your Name:</TD>
                                                                                                                  <TD>
                                                                                                                        <asp:textbox id="txtName" runat="server"></asp:textbox></TD>
                                                                                                            </TR>
                                                                                                            <TR>
                                                                                                                  <TD width="147">Your Email Address:</TD>
                                                                                                                  <TD>
                                                                                                                        <asp:textbox id="txtEmail" runat="server"></asp:textbox></TD>
                                                                                                            </TR>
                                                                                                            <TR>
                                                                                                                  <TD width="147">Your Work Base:</TD>
                                                                                                                  <TD>
                                                                                                                        <asp:textbox id="txtLocation" runat="server"></asp:textbox></TD>
                                                                                                            </TR>
                                                                                                      </TABLE>
                                                                                                <P>
                                                                                                      <asp:CheckBoxList id="formResults" runat="server" DataValueField="FormID" DataTextField="FormName"></asp:CheckBoxList><BR>
                                                                                                      <asp:button id="btnSendFeedback" onclick="btnSendFeedback_Click" runat="server" Text="Request Forms"></asp:button>
                                                                                          </FORM>
                                                                                    </asp:panel>
                                                                              </P>
                                                                              <P>
                                                                                    <asp:panel id="panelMailSent" runat="server" Visible="False">
                                                                                          <P>
                                                                                                <H2>Thank You</H2>
                                                                                          <P>Your forms have been requested and will be posted out to you shortly.</P>
                                                                                    </asp:panel>
                                          
                                                                              <P><IMG height="1" src="../images/spacer.gif" width="733"></P>
                                                                        </div>
                                                                  </td>
                                                            </tr>
                                                      </table>
                                                </td>
                                          </tr>
                                    </table>
                              </DIV>
                              <DIV align="center">
                                    <table cellSpacing="0" cellPadding="0" width="100%" align="center" bgColor="#0f298f">
                                          <tr>
                                                <td width="100%"><IMG height="8" src="../images/spacer.gif" width="1">
                                                </td>
                                          </tr>
                                    </table>
                              </DIV>
                        </td>
                        <td>&nbsp;
                        </td>
                  </tr>
            </table>
      </body>
</HTML>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lucinda_rhian
ID: 13438707
ahh!  I was trying to post a well-formatted cut down version of my page - but pressed send too soon - I giess you cant edit your own posts here then!
0
 
LVL 10

Expert Comment

by:NetDeveloper
ID: 13438735
# 1 set the DataValueField / DataTextField = to a column of a db field for formResults

#2 do the binding of the checkbox list formResults when Page.IsPostback=false
0
 

Author Comment

by:lucinda_rhian
ID: 13440537
I have done both these things but still no luck!
0
 

Author Comment

by:lucinda_rhian
ID: 13440644
A slightly more readable version of the code!

<%@ Page Language="VB"%>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web.Mail" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
  <HEAD>
    <title>Form Request</title>
    <script language="VB" runat="server">
      sub Page_Load(sender as Object, e as EventArgs)
   
        Dim connString as String
        connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\Inetpub\wwwroot\intranet\forms\btforms.mdb;"
        Dim objConnection as OleDbConnection
        objConnection = New OleDbConnection(connString)
        objConnection.Open()
        Dim strSQL as String = "SELECT * FROM Forms WHERE AvailableElectronically=false"
        Dim objCommand as OleDbCommand
        objCommand = New OleDbCommand(strSQL, objConnection)
        Dim objDataReader as OleDbDataReader
        objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
        Page.IsPostback=false
        formResults.DataSource = objDataReader
        formResults.DataBind()    
        objDataReader.Close()

      end sub
                  
      Sub btnSendFeedback_Click(sender as Object, e as EventArgs)

        Dim objMM as New MailMessage()
        objMM.To = "me@somedomain.com"
        objMM.From = txtEmail.Text
        objMM.BodyFormat = MailFormat.Text
        objMM.Priority = MailPriority.Normal
        objMM.Subject = "BT Form Request"
      
        Dim item As ListItem
        Dim txt1 As String
      
        For Each item In formResults.Items
          If item.Selected = True Then
            txt1 &= item.Text & ", "
          End If
        Next

        objMM.Body = txt1
        SmtpMail.SmtpServer = "smtp.somedomain.com"
        SmtpMail.Send(objMM)
        panelSendEmail.Visible = false
        panelMailSent.Visible = true

      End Sub
    </script>
  </HEAD>
  <body>
    <h1 align="center">Hard Copy Forms Request</h1>
    <asp:panel id="panelSendEmail" runat="server">
      <P>Please request forms not available electronically by filling in the form below:</P>    
      <FORM id="Form1" runat="server">
        <TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="0">
          <TR>
            <TD width="147">Your Name:</TD>
            <TD><asp:textbox id="txtName" runat="server"/></TD>
              </TR>
          <TR>
            <TD width="147">Your Email Address:</TD>
            <TD><asp:textbox id="txtEmail" runat="server"/></TD>
          </TR>
          <TR>                                                                  <TD width="147">Your Work Base:</TD>
      <TD><asp:textbox id="txtLocation" runat="server"/></TD>                               
          </TR>
        </TABLE>
        <asp:CheckBoxList id="formResults"                        
                                    runat="server"
                                    DataValueField="FormName"
                                    DataTextField="FormName"/>
        <BR>
        <asp:button id="btnSendFeedback" onclick="btnSendFeedback_Click" runat="server" Text="Request Forms"/>          
      </FORM>
    </asp:panel>
   
    <asp:panel id="panelMailSent" runat="server" Visible="False">
      <H2>Thank You</H2>
      <P>Your forms have been requested and will be posted out to you shortly.</P>
    </asp:panel>
  </body>
</HTML>
0
 
LVL 10

Accepted Solution

by:
NetDeveloper earned 800 total points
ID: 13440677
Hi,

Page.IsPostback=false
        formResults.DataSource = objDataReader
        formResults.DataBind()    


is not correct

it must be

If Page.IsPostback=false Then
        formResults.DataSource = objDataReader
        formResults.DataBind()    
End If

try now :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

770 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