Here's some background for the issue. I have a gridview which displays applications for membership to our site. When I click the "Approve" button, it basically transfers data from the application table to the users table. Also, I would like, when the "Approve" button is fired, to send an html email to the user letting them know they are now approved to use the site.
Below is my (relevant) code for firing off the email. My problem is that in the line "email = CType(email, BoundField)", intellisense says that the second "email" ...Variable email is used before it has been assigned. A Null reference exception could result at runtime. I suspect it has something to do with the line "strTo.DataField" but I'm not sure.
Any ideas are appreciated.
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName = "Approve" Then
Dim gv As GridView = GridView1
Dim colFields As DataControlFieldCollection = gv.Columns
For Each colField As DataControlField In colFields
If TypeOf colField Is BoundField Then
Dim email As BoundField
email = CType(email, BoundField)
Dim strFrom = "email@example.com"
Dim strTo = email
Dim MailMsg As New MailMessage(New MailAddress(strFrom), New MailAddress(strTo.DataField))
Dim Body As String ="a bunch of html code"
MailMsg.BodyEncoding = Encoding.Default
MailMsg.Subject = "Welcome!"
MailMsg.Body = Body
MailMsg.Priority = MailPriority.High
MailMsg.IsBodyHtml = True
'Smtpclient to send the mail message
Dim SmtpMail As New SmtpClient
SmtpMail.Host = "localhost"