Email Datagrid problem

olud

New member
Joined
Mar 2, 2008
Messages
1
Programming Experience
Beginner
Please help!!!

i am greating a nested datagrd and i want to email the content of each row, including the nested datagrid (as individual emails)to an email address

i keep getting multiple emails per row. please tell me what i am doing wrong

VB.NET:
 Private Sub DataGrid2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid2.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim gv As DataGrid = DirectCast(e.Item.FindControl("datagrid3"), DataGrid)
            Dim intRow As Integer = 0
            Dim strName As String = ""
            Dim strPercent As String = ""
            Dim dblTotal As Double = 0
            Dim dblPercent As Double = 0
            '
            ' Number of rows in the DataGrid
            '
            Dim intRows As Integer = DataGrid2.Items.Count - 1
            'Dim blnChecked As Boolean = False
            '
            ' DataGrid rows are really DataGridItems.
            '
            Dim GridItem As DataGridItem
            For intRow = 0 To intRows
                '
                ' Get the grid row.
                '
                Dim Intid = DataGrid2.Items(intRow).Cells(0).Text

                Dim ds2 As New DataSet
                Dim str
                ' str = ds2.Tables(0).Rows(0).Item("email")


                Dim cnn2 As New SqlConnection("Data Source=21.21.21.12,;Initial Catalog=bj;User ID=xxxx;Password=xxxx")
                Dim cmd2 As New SqlDataAdapter("SELECT top 10  email,vacID FROM jbe_match WHERE usID = '" & Intid & "'", cnn2)
                'Create and fill the DataSet.

                cmd2.Fill(ds2, "jbe_match")
                gv.DataSource = ds2
                gv.DataBind()


                Dim SB As New StringBuilder
            Dim SW As New StringWriter(SB)
            Dim htmlTW As New HtmlTextWriter(SW)
            gv.RenderControl(htmlTW)

            Dim dataGridHTML As String = SB.ToString()


            'Render DataGrid output as Html

            ' gv.RenderControl(hw)
            ' Dim dataGridHTML As String = hw.ToString()
            Dim Mail As New MailMessage
            Mail.From = "support@email.net"
            Mail.To = "somebody@yahoo.co.uk"
            Mail.Cc = ""
            Mail.Bcc = ""
            Mail.Subject = "Requested Eligibility Change - " & e.Item.Cells(1).Text
            Mail.BodyFormat = MailFormat.Html
            Mail.Body = dataGridHTML
            Mail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
            Mail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "supp@bxxxxxxxx"
            Mail.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxx"


            SmtpMail.SmtpServer = "22.24.17.10"
            SmtpMail.Send(Mail)
            Next

        End If
end sub
 
Back
Top