E-Mail GridView ASP.net

I am trying to email a gridview that has user selected QTY's and Calculated Totals.
The Totals are being calculated Via a Javascript.  Please see this page to see how we accomplished this.  http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_25629261.html

(I switched to Javascript because i did not want a postback to happen evertime a qty is selected.)

I currently have the CodeBehind Getting the gridview and then turning it into html and then emailing it.

But with new javascript in place to do the calculations,  The Totals never come over on the email.

Please see the Code Box


Thank You.
--- Emailing with CodeBehind doing the calculations ---
<tr class="RowStyle">
			<td>P548440</td><td>
                                    <div>
            <img id="GridView1_ctl27_Image1" onerror="DisplayDefaultImage(this)" onmouseover="ShowBiggerImage(this);" onmouseout="ShowDefaultImage(this);" src="/se/images/items/i17479.jpg" style="width:20px;border-width:0px;" />
            </div>
                            </td><td>EA</td><td>BP UNIT COMPLETE ADULT NAVY</td><td>10/1/2009</td><td>
                                <span id="GridView1_ctl27_Price">$16.12</span>
                            </td><td style="font-size:Medium;font-weight:bold;">
                                6
                                <span id="GridView1_ctl27_lblOrderStatus"></span>
                            </td><td>
                                <span id="GridView1_ctl27_Totals">$96.72</span>
                            </td>
		</tr>



--- Emailing with the Javascript doing calculations ---

<tr class="AltRowStyle">
			<td>P150145</td><td>
                                    <div>
                                   
            <img id="GridView1_ctl15_Image1" onerror="DisplayDefaultImage(this)" onmouseover="ShowBiggerImage(this);" onmouseout="ShowDefaultImage(this);" src="/se/images/items/i19012.jpg" style="width:20px;border-width:0px;" />
            </div>
                            </td><td>BX</td><td>BANDAGES, 3/4X3, SHEER, L/F, 100/BX</td><td>
                                <span id="GridView1_ctl15_Price">$1.65</span>
                            </td><td style="font-size:Medium;font-weight:bold;">
4
                                <span id="GridView1_ctl15_lblOrderStatus"></span>
                            </td><td>
                                <span id="GridView1_ctl15_Totals"></span>
                                

                            </td>
		</tr>



--- Here is the code that i am using to do the emails ---

Private Sub DisableControls(ByVal gv As Control)
        Dim lb As New LinkButton()
        Dim l As New Literal()

        Dim name As String = [String].Empty

        For i As Integer = 0 To gv.Controls.Count - 1
            If gv.Controls(i).[GetType]() Is GetType(LinkButton) Then
                l.Text = TryCast(gv.Controls(i), LinkButton).Text
                gv.Controls.Remove(gv.Controls(i))
                gv.Controls.AddAt(i, l)

            ElseIf gv.Controls(i).[GetType]() Is GetType(DropDownList) Then
                l.Text = TryCast(gv.Controls(i), DropDownList).SelectedItem.Text
                gv.Controls.Remove(gv.Controls(i))
                gv.Controls.AddAt(i, l)
            End If


            If gv.Controls(i).HasControls() Then
                DisableControls(gv.Controls(i))
            End If

        Next
    End Sub


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        DisableControls(GridView1)
        'Dim CustomerEmail As String = CustomerCC.Text
        Dim Customer As String = Session("Customer_ID")
        Dim SpecialNotes As String = SpecNotes.Text
        Dim SB As StringBuilder = New StringBuilder()
        Dim SW As StringWriter = New StringWriter(SB)
        Dim htmlTW As HtmlTextWriter = New HtmlTextWriter(SW)
        Dim htmlfrm As HtmlForm = New HtmlForm()

        htmlfrm.Controls.Add(GridView1)

        GridView1.RenderControl(htmlTW)

        Dim GridViewHTML As String = SB.ToString()
        Dim strtoemail As String = Nothing
        'Dim CCstrtoemail As String = Nothing
        'Dim BCCstrtoemail As String = Nothing
        strtoemail = Session("Email")
        'CCstrtoemail = CustomerCC.Text
        'BCCstrtoemail = "user@domain.com"

        ' email code //

        Dim emailorders As MailMessage = New MailMessage()
        Dim mySmtpClient As SmtpClient = Nothing
        emailorders.From = New MailAddress("user@domain.com")
        emailorders.To.Add(Session("Email"))
        'emailorders.CC.Add((BCCstrtoemail))
        'emailorders.Bcc.Add((BCCstrtoemail))

        emailorders.Subject = " Order Confirmation for " + Customer
        emailorders.IsBodyHtml = "True"

        Dim embody As StringBuilder = New StringBuilder()
        Dim ebody As String = Nothing
        ebody = "<strong>Order Details For Customer Number: </strong>" + Customer + "<br />" + "<hr /><strong>NOTES: </strong>" + SpecialNotes + "<hr />" + GridViewHTML
        embody.AppendLine()
        embody.Append(ebody)


        emailorders.Body = embody.ToString()
        mySmtpClient = New SmtpClient("**.**.**.**")
        mySmtpClient.Port = "25"
        mySmtpClient.Send(emailorders)

        Response.Write("<strong> Order Has Been Sent!!! </strong>")


        'ltloutput.Text = Server.HtmlEncode(GridViewHTML);
        Button1.Visible = "False"
        SpecNotes.Visible = "False"
        notelbl.Visible = "False"

    End Sub

Open in new window

LVL 6
phoenixfire425Asked:
Who is Participating?
 
phoenixfire425Connect With a Mentor Author Commented:
Is there a way to rebind the calculated vales to an ASP:Label?
0
 
leakim971PluritechnicianCommented:
Hello phoenixfire425,

You may add an hidden field in your span :

replace :

by :
<input type="hidden" id="Hidden_Total" />

and you update it too in the javascript function (see the last line) :


function TotalUnitPrice() {
			var table = document.getElementById("GridView1");
			var rows = table.getElementsByTagName("tr");
			total = 0;
			for(var t=1;t<rows.length-1;t++) {
				var cells = rows[t].getElementsByTagName("td");
				var price = cells[4].getElementsByTagName("span")[0].innerHTML;
				var qty = cells[5].getElementsByTagName("select")[0].value;
				var subtotalrow = parseFloat( price.replace("$","") ) * qty;
				total += parseFloat( price.replace("$","") ) * qty;
				cells[6].getElementsByTagName("span")[0].innerHTML = "$" + subtotalrow.toFixed(2);
			}
			rows[rows.length-1].getElementsByTagName("span")[1].innerHTML = "$" + total.toFixed(2);
                        document.getElementById("Hidden_Total").value = "$" + total.toFixed(2);
		}

Open in new window

0
 
phoenixfire425Author Commented:
I changed the Javascipt to the above and then changed my gridview footer to this
                           
                            <FooterTemplate>
                                <asp:Label runat="server" ID="SubTotals"></asp:Label>
                                <asp:Label ID="lblTotal" runat="server"></asp:Label>
                                <input type="hidden" id="Hidden_Total" />                            
                            </FooterTemplate>

And after getting the email there is nothing in the email that has the total in it.  Also none of the item totals are showing in the email either.

Also i dont think that you can display a TextBox in and HTML email without it being some kind of WebMail..  I figured that out when i was originally starting this project. and that is why i witched to DropDown Boxes.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
leakim971PluritechnicianCommented:
of course :

document.getElementById("Label_Total").innerHTML  = "$" + total.toFixed(2);
0
 
phoenixfire425Author Commented:
Nope does not look like that worked.

Here is the HTML that came from the EMAIL.

<strong>Order Details For Customer Number: </strong>112258<br /><hr /><strong>NOTES: </strong><hr /><div>
	<table class="GridViewStyle" cellspacing="0" rules="all" border="1" id="GridView1" style="border-collapse:collapse;">
		<tr class="HeaderStyle">
			<th scope="col"><a href="javascript:__doPostBack('GridView1','Sort$item_id')">Item ID</a></th><th scope="col">&nbsp;</th><th scope="col"><a href="javascript:__doPostBack('GridView1','Sort$UOM')">Unit of Measure</a></th><th scope="col"><a href="javascript:__doPostBack('GridView1','Sort$item_desc')">Item Description</a></th><th scope="col"><a href="javascript:__doPostBack('GridView1','Sort$price')">Price</a></th><th scope="col">Qty</th><th scope="col">Extended Price</th>
		</tr><tr class="RowStyle">
			<td>K5150</td><td>
                                    <div>
                                   
            <img id="GridView1_ctl14_Image1" onerror="DisplayDefaultImage(this)" onmouseover="ShowBiggerImage(this);" onmouseout="ShowDefaultImage(this);" src="/se/images/items/i10252.jpg" style="width:20px;border-width:0px;" />
            </div>
                            </td><td>BX</td><td>ALCOHOL PREP PADS   MED   200/BX</td><td>
                                <span id="GridView1_ctl14_Price">$1.33</span>
                            </td><td style="font-size:Medium;font-weight:bold;">
4
                                <span id="GridView1_ctl14_lblOrderStatus"></span>
                            </td><td>
                                <span id="GridView1_ctl14_Totals"></span>
                                

                            </td>
		</tr><tr class="AltRowStyle">
			<td>P150145</td><td>
                                    <div>
                                   
            <img id="GridView1_ctl15_Image1" onerror="DisplayDefaultImage(this)" onmouseover="ShowBiggerImage(this);" onmouseout="ShowDefaultImage(this);" src="/se/images/items/i19012.jpg" style="width:20px;border-width:0px;" />
            </div>
                            </td><td>BX</td><td>BANDAGES, 3/4X3, SHEER, L/F, 100/BX</td><td>
                                <span id="GridView1_ctl15_Price">$1.65</span>
                            </td><td style="font-size:Medium;font-weight:bold;">
14
                                <span id="GridView1_ctl15_lblOrderStatus"></span>
                            </td><td>
                                <span id="GridView1_ctl15_Totals"></span>
                                

                            </td>
		</tr><tr class="RowStyle">
			<td>P159025</td><td>
                                    <div>
                                   
            <img id="GridView1_ctl16_Image1" onerror="DisplayDefaultImage(this)" onmouseover="ShowBiggerImage(this);" onmouseout="ShowDefaultImage(this);" src="/se/images/items/i17418.jpg" style="width:20px;border-width:0px;" />
            </div>
                            </td><td>BG</td><td>COTTON BALLS, MED, 2000/BG</td><td>
                                <span id="GridView1_ctl16_Price">$6.06</span>
                            </td><td style="font-size:Medium;font-weight:bold;">
0
                                <span id="GridView1_ctl16_lblOrderStatus"></span>
                            </td><td>
                                <span id="GridView1_ctl16_Totals"></span>
                                

                            </td>
		</tr><tr class="AltRowStyle">
			<td>RT-24</td><td>
                                    <div>
                                   
            <img id="GridView1_ctl17_Image1" onerror="DisplayDefaultImage(this)" onmouseover="ShowBiggerImage(this);" onmouseout="ShowDefaultImage(this);" src="/se/images/items/i10061.jpg" style="width:20px;border-width:0px;" />
            </div>
                            </td><td>PK</td><td>ELECTRODE RESTING EKG TAB</td><td>
                                <span id="GridView1_ctl17_Price">$3.44</span>
                            </td><td style="font-size:Medium;font-weight:bold;">
0
                                <span id="GridView1_ctl17_lblOrderStatus"></span>
                            </td><td>
                                <span id="GridView1_ctl17_Totals"></span>
                                

                            </td>
		</tr><tr class="RowStyle">
			<td>P157117</td><td>
                                    <div>
                                   
            <img id="GridView1_ctl18_Image1" onerror="DisplayDefaultImage(this)" onmouseover="ShowBiggerImage(this);" onmouseout="ShowDefaultImage(this);" src="" style="width:20px;border-width:0px;" />
            </div>
                            </td><td>PK</td><td>GAUZE PAD  4X4 N/S  8-PLY</td><td>
                                <span id="GridView1_ctl18_Price">$2.32</span>
                            </td><td style="font-size:Medium;font-weight:bold;">
11
                                <span id="GridView1_ctl18_lblOrderStatus"></span>
                            </td><td>
                                <span id="GridView1_ctl18_Totals"></span>
                                

                            </td>
		</tr><tr class="AltRowStyle">
			<td>164200</td><td>
                                    <div>
                                   
            <img id="GridView1_ctl19_Image1" onerror="DisplayDefaultImage(this)" onmouseover="ShowBiggerImage(this);" onmouseout="ShowDefaultImage(this);" src="/se/images/items/i09967.jpg" style="width:20px;border-width:0px;" />
            </div>
                            </td><td>BX</td><td>GLOVE   LATEX  P/F  MED  INNOVAGRIP</td><td>
                                <span id="GridView1_ctl19_Price">$3.95</span>
                            </td><td style="font-size:Medium;font-weight:bold;">
0
                                <span id="GridView1_ctl19_lblOrderStatus"></span>
                            </td><td>
                                <span id="GridView1_ctl19_Totals"></span>
                                

                            </td>
		</tr><tr class="RowStyle">
			<td>115200</td><td>
                                    <div>
                                   
            <img id="GridView1_ctl20_Image1" onerror="DisplayDefaultImage(this)" onmouseover="ShowBiggerImage(this);" onmouseout="ShowDefaultImage(this);" src="/se/images/items/i05014.jpg" style="width:20px;border-width:0px;" />
            </div>
                            </td><td>BX</td><td>GLOVE  LATEX  MED DERMASSIST</td><td>
                                <span id="GridView1_ctl20_Price">$4.23</span>
                            </td><td style="font-size:Medium;font-weight:bold;">
11
                                <span id="GridView1_ctl20_lblOrderStatus"></span>
                            </td><td>
                                <span id="GridView1_ctl20_Totals"></span>
                                

                            </td>
		</tr><tr class="AltRowStyle">
			<td>7400</td><td>
                                    <div>
                                   
            <img id="GridView1_ctl21_Image1" onerror="DisplayDefaultImage(this)" onmouseover="ShowBiggerImage(this);" onmouseout="ShowDefaultImage(this);" src="/se/images/items/i03933.jpg" style="width:20px;border-width:0px;" />
            </div>
                            </td><td>PK</td><td>OTOSCOPE SPECULA, 4MM, DISP,</td><td>
                                <span id="GridView1_ctl21_Price">$19.78</span>
                            </td><td style="font-size:Medium;font-weight:bold;">
14
                                <span id="GridView1_ctl21_lblOrderStatus"></span>
                            </td><td>
                                <span id="GridView1_ctl21_Totals"></span>
                                

                            </td>
		</tr><tr class="RowStyle">
			<td>P080063</td><td>
                                    <div>
                                   
            <img id="GridView1_ctl22_Image1" onerror="DisplayDefaultImage(this)" onmouseover="ShowBiggerImage(this);" onmouseout="ShowDefaultImage(this);" src="" style="width:20px;border-width:0px;" />
            </div>
                            </td><td>BX</td><td>PREGNANCY HCG TEST  PRO ADVANTAGE</td><td>
                                <span id="GridView1_ctl22_Price">$18.95</span>
                            </td><td style="font-size:Medium;font-weight:bold;">
0
                                <span id="GridView1_ctl22_lblOrderStatus"></span>
                            </td><td>
                                <span id="GridView1_ctl22_Totals"></span>
                                

                            </td>
		</tr><tr class="AltRowStyle">
			<td>2161</td><td>
                                    <div>
                                   
            <img id="GridView1_ctl23_Image1" onerror="DisplayDefaultImage(this)" onmouseover="ShowBiggerImage(this);" onmouseout="ShowDefaultImage(this);" src="/se/images/items/i10364.jpg" style="width:20px;border-width:0px;" />
            </div>
                            </td><td>BX</td><td>URINALYSIS STRIPS MULTISTIX 10SG</td><td>
                                <span id="GridView1_ctl23_Price">$39.25</span>
                            </td><td style="font-size:Medium;font-weight:bold;">
18
                                <span id="GridView1_ctl23_lblOrderStatus"></span>
                            </td><td>
                                <span id="GridView1_ctl23_Totals"></span>
                                

                            </td>
		</tr><tr class="RowStyle">
			<td>2001</td><td>
                                    <div>
                                   
            <img id="GridView1_ctl24_Image1" onerror="DisplayDefaultImage(this)" onmouseover="ShowBiggerImage(this);" onmouseout="ShowDefaultImage(this);" src="/se/images/items/i09766.jpg" style="width:20px;border-width:0px;" />
            </div>
                            </td><td>BX</td><td>URINALYSIS STRIPS, REDISCREEN,</td><td>
                                <span id="GridView1_ctl24_Price">$21.95</span>
                            </td><td style="font-size:Medium;font-weight:bold;">
0
                                <span id="GridView1_ctl24_lblOrderStatus"></span>
                            </td><td>
                                <span id="GridView1_ctl24_Totals"></span>
                                

                            </td>
		</tr><tr>
			<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>
                            </td><td>&nbsp;</td><td>
                                <span id="GridView1_ctl25_SubTotals"></span>
                                <span id="GridView1_ctl25_lblTotal"></span>
                                <input  id="Hidden_Total" />                            
                            </td>
		</tr>
	</table>
</div>

Open in new window

0
 
phoenixfire425Author Commented:
Any idea?
Is it possible to take the Gridview and the Notes textbox and then email them with Javascript??
0
 
leakim971PluritechnicianCommented:
>document.getElementById("Label_Total").innerHTML  = "$" + total.toFixed(2);
You let the  <input  id="Hidden_Total" />  at the end...

and you said me :
>Is there a way to rebind the calculated vales to an ASP:Label?

So replace the input by an asp:label no ?
0
 
phoenixfire425Author Commented:
I could not get these to send Via Email.
They just appear blank in the email.
0
 
leakim971PluritechnicianCommented:
Currently, what are you able to see in the email ? Do you see GLOVE  LATEX  MED DERMASSIST ?
0
 
phoenixfire425Author Commented:
Sorry this has taken me a while i was out on medical leave :/

But i am going to start this project back up this week so i will post back soon!

Thank You
0
 
leakim971Connect With a Mentor PluritechnicianCommented:
ok
0
 
phoenixfire425Author Commented:
We ended up scrapping this part and actually built a cart system.

But I did try to get it to work and when it runs it does not see the text boxes upon email.

But thank you for trying to help.
0
All Courses

From novice to tech pro — start learning today.