Reading values from a Gridview

I am building a small web app for managing tasks and I have the following code which lets me Edit a row in gridview and then select a resource, when I update that row the code then looks up the resources email address and then send an email with the details of what was in that row. My issue is the last part, how can I read all the other information in that row and assign to variables ?
I used e.NewValues(5).ToString() to retrieve the resource name, but need to retrieve the other row details to be included in the email.

Any ideas ?

Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As GridViewUpdatedEventArgs)
        ' Indicate whether the update operation succeeded.
        If e.Exception Is Nothing Then
            Dim strEmail As String
            strEmail = String.Empty
            Dim Resource As String = e.NewValues(5).ToString()

            'Retrieve email address
            Dim cm As New SqlCommand("SELECT Res_Email FROM Resource_ref_Data WHERE Resource = @FirstName")
            Dim param As New SqlParameter("@FirstName", Resource)
            Dim cn As New SqlConnection("Data Source=server1;Initial Catalog=EMS;Persist Security Info=True;User ID=user;Password=xxxxxx")
            cm.Connection = cn
            Dim oResult As Object
            If cn.State = ConnectionState.Closed Then
            End If
            oResult = cm.ExecuteScalar()
            If (Not oResult Is Nothing) Then
                strEmail = oResult.ToString()
            End If
            e.ExceptionHandled = True
            Response.Write("An error occurred while attempting to update the row. No email sent.")

        End If
    End Sub

    Private Function currentRow() As Object
        Throw New NotImplementedException
    End Function

    Protected Sub SendMailResource(ByVal strEmailAddress As String)
        Dim mail As New MailMessage()
        'set the addresses

        Dim sEmailBody As String
        sEmailBody = My.Resources.Resource1.Resource_Email

        'sEmailBody = sEmailBody.Replace("[strEnv]", strEnv)
        'sEmailBody = sEmailBody.Replace("[strBuild]", )
        'sEmailBody = sEmailBody.Replace("[strComponent]", )
        'sEmailBody = sEmailBody.Replace("[strSubComponent]", )
        'sEmailBody = sEmailBody.Replace("[strResource]", )
        'sEmailBody = sEmailBody.Replace("[strComments]", )
        'sEmailBody = sEmailBody.Replace("[strDate]", )
        'sEmailBody = sEmailBody.Replace("[strDoc]", )

        mail.From = New MailAddress("")
        'set the content
        mail.Subject = "Task Awaiting"
        mail.Body = sEmailBody
        mail.IsBodyHtml = True
        'send the message
        Dim smtp As New SmtpClient("smtp1")
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    End Sub

Open in new window

Who is Participating?

Improve company productivity with a Business Account.Sign Up

CodeCruiserConnect With a Mentor Commented:
Just like you pass the email address.


Protected Sub SendMailResource(ByVal strEmailAddress As String)


Protected Sub SendMailResource(ByVal strEmailAddress As String, ByVal strEnv As String)




Dim strEnv As String = e.NewValues(1)
SendMailResource(strEmail, strEnv)
>I used e.NewValues(5).ToString() to retrieve the resource name



to get values for other columns.
ndr-itsolutionsAuthor Commented:
I tried that and it did not work, could be my coding though, as I am new to this.

So I added the following to the gridview sub routine:

Dim strEnv As String = e.NewValues(1) 

Open in new window


sEmailBody = sEmailBody.Replace("[strEnv]", strEnv)

Open in new window

to the SendMail Resource routine and got the following message, stating strEnv was not declared ??
Error Message
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Is the variable in the same sub as the email body code? Otherwise, that variable cannot be seen. And this issue is not related to gridview.
ndr-itsolutionsAuthor Commented:
Not it's not in the same sub, what's the best way to fix this issue ? Put the email sub into the gridview sub ?
Or pass that value into email sub.
ndr-itsolutionsAuthor Commented:
Do you have an example of the code I would use to pass the values I need ?
ndr-itsolutionsAuthor Commented:
That worked perfectly
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.