Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Gridview and column updates

Posted on 2013-02-04
12
Medium Priority
?
357 Views
Last Modified: 2013-02-11
I have an email which sucessfully fires when a row is edited\updated in a gridview, however it fires on the editing of anything in that current selected row.
How I can make it fire an email when say for instance, a column that contains the field status is set to 'complete', basically rather than firing once the row is updated, I would like to be a bit more specific.

Ideally, I want an email to be sent once the task has been 'Assigned' and a different email fired when a task has been 'Completed'

Any ideas ?
0
Comment
Question by:ndr-itsolutions
[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
  • 6
  • 5
12 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 38852282
Please show the code for gridview updating.
0
 

Author Comment

by:ndr-itsolutions
ID: 38853180
 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()
            Dim strEnv As String = e.NewValues(2).ToString()
            Dim strBuild As String = e.NewValues(3).ToString()
            Dim strComponent As String = e.NewValues(1).ToString()
            Dim strSubComponent As String = e.NewValues(4).ToString()
            Dim strResource As String = e.NewValues(5).ToString()
            Dim strComments As String = e.NewValues(10).ToString()
            Dim strDate As String = e.NewValues(7).ToString()
            Dim strDoc As String = e.NewValues(15).ToString()
            Dim strSoft As String = e.NewValues(12).ToString()
            Dim strID As String = e.NewValues(0).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)
            cm.Parameters.Add(param)
            Dim cn As New SqlConnection("Data Source=server1;Initial Catalog=FFF;Persist Security Info=True;User ID=users;Password=xxxxxx")
            cm.Connection = cn
            Dim oResult As Object
            If cn.State = ConnectionState.Closed Then
                cn.Open()
            End If
            oResult = cm.ExecuteScalar()
            If (Not oResult Is Nothing) Then
                strEmail = oResult.ToString()
            End If
            SendMailResource(strEmail, strEnv, strBuild, strComponent, strSubComponent, strResource, strComments, strDate, strDoc, strSoft, strID)
        Else
            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, ByVal strEnv As String, ByVal strBuild As String, ByVal strComponent As String, ByVal strSubComponent As String, ByVal strResource As String, ByVal strComments As String, ByVal strDate As String, ByVal strDoc As String, ByVal strSoft As String, ByVal strID As String)
        Dim mail As New MailMessage()
        'set the addresses

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

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


        mail.From = New MailAddress("test@test.com")
        mail.To.Add("test@test.com")
        mail.To.Add(strEmailAddress)
        'set the content
        mail.Subject = "TEST"
        mail.Body = sEmailBody
        mail.IsBodyHtml = True
        'send the message
        Dim smtp As New SmtpClient("relay.server")
        smtp.Send(mail)
    End Sub
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
       
    End Sub

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38854427
>Dim Resource As String = e.NewValues(5).ToString()

You are using the NewValues collection. You can similarly use the OldValues collection so that you can do some checks. For example

If e.OldValues(IndexOfStatusColumn) = "Unassigned" And e.NewValues(IndexOfStatusColumn)  = "Assigned" Then
     'Code to send the assigned email
Else If e.OldValues(IndexOfStatusColumn) = "Assigned" And e.NewValues(IndexOfStatusColumn)  = "Completed" Then
     'Code to send the completed email
End If
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:ndr-itsolutions
ID: 38858795
If the value does not show 'UnAssigned' it will show the name of the resource, how would that work with that code you have supplied ?

Same with 'Completed' other choices are 'Not Deployed' or 'In Progress'

I presume I would insert this code just below :

Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As GridViewUpdatedEventArgs)
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38859023
Yes code will go in RowUpdated event.


You can modify those if conditions to work the way you want.
0
 

Author Comment

by:ndr-itsolutions
ID: 38859278
I'm not sure about the 'if' statement, would I use not equal to if I have multiple resources to choose from?
0
 

Author Comment

by:ndr-itsolutions
ID: 38859345
I can't seem to get this working at all.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38859639
What would be the possible values of status?

Unassigned
Name Of Some Resource
In Progress
Not Deployed
Completed

Is that correct?
0
 

Author Comment

by:ndr-itsolutions
ID: 38860017
So the values for the status column are:
Completed
In progress
Not Started
Not deployed
Raised

And the values in the resource column are

UnAssigned
Nick Smith
Andy Smith
Another person
Ben Smith
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 38863489
You need to put if conditions based on your workflow. So if the workflow is

Not Started->In Progress->Not Deployed->Raised->Completed

And you need to send emails at each status change then you can put a condition like below

If e.OldValues(statuscolumnindex) = "Not Started" AND e.NewValues(statuscolumnindex)="In Progress" Then
   'Send email
Else If e.OldValues(statuscolumnindex) = "In Progress" AND e.NewValues(statuscolumnindex)="Not Deployed" Then
   'Send another email
...
End If
0
 

Author Comment

by:ndr-itsolutions
ID: 38867557
So i would add that condition under the Rowupdated sub and copy all subsequent code into where you have commented 'Send Email ?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38869176
Yes.
0

Featured Post

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!

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

618 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