I am a newbie at ASP so I am hoping someone can assist me with being able to format Web field background colors like in Excel. I want to have the bgcolor of a cell on a results page from a SQL query be red if the amount is below 90 and be yellow if 90 to 95 and green if above 95. Any help on syntax or where to start is greatly appreciated.
russell
01-06-2007, 11:17 PM
Dim bgcolor
If someVar < 90 Then
bgcolor = "red"
ElseIf someVar < 96 Then
bgcolor = "yellow"
Else
bgcolor = "green"
End If
If Clng(AHTDirSum.Fields.Item("AHT").Value)) > 450 Then
bgcolor = "red"
ElseIf Clng(AHTDirSum.Fields.Item("AHT").Value) < 335 Then
bgcolor = "yellow"
Else
bgcolor = "green"
End If
Chamark
01-07-2007, 03:15 PM
I've tried to make it even more simple with just red & green and still get all green (see code). Thanks
<%Dim bgcolor
If Clng(AHTDirSum.Fields.Item("AHT").Value) < (AHTDirSum.Fields.Item("Goal").Value) Then
bgcolor = "green"
Else
bgcolor = "red"
End If
%>
If Clng(AHTDirSum.Fields.Item("AHT").Value) < Clng(AHTDirSum.Fields.Item("Goal").Value) Then
also, what is the value of "AHT" and "Goal" ?
what does style12 apply to the span?
oh, wait....
this
If Clng(AHTDirSum.Fields.Item("AHT").Value) < (AHTDirSum.Fields.Item("Goal").Value) Then
bgcolor = "green"
Else
bgcolor = "red"
End If
needs to be right after this line:
While ((Repeat1__numRows <> 0) AND (NOT AHTDirSum.EOF))
Chamark
01-07-2007, 05:24 PM
try
If Clng(AHTDirSum.Fields.Item("AHT").Value)) > 450 Then
bgcolor = "red"
ElseIf Clng(AHTDirSum.Fields.Item("AHT").Value) < 335 Then
bgcolor = "yellow"
Else
bgcolor = "green"
End If
_______________________________________________________________
OK I've tried a different approach (see the following code) and get the right colors but my AHT column is blank and it writes my colors in the Talk Time column. I'd also like to be able to use formatnumber in the syntax. Any help is
appreciated.
<tr>
<td><span class="style2">Director</span></td>
<td><span class="style2">Segment</span></td>
<td><span class="style2">Calls</span></td>
<td><span class="style2">AHT</span></td>
<td><span class="style2">Talk Time</span></td>
<td><span class="style2">Wrap Time</span></td>
<td><span class="style2">Hold Time</span></td>
<td><span class="style2">Goal</span></td>
<td><span class="style2">Variance</span></td>
</tr>
<% While ((Repeat1__numRows <> 0) AND (NOT AHTDirSum.EOF)) %>
<tr>
<td><span class="style12"><%=(AHTDirSum.Fields.Item("Director").Value)%></span></td>
<td><span class="style12"><%=(AHTDirSum.Fields.Item("Segment").Value)%></span></td>
<td><span class="style12"><%=(AHTDirSum.Fields.Item("Calls").Value)%></span></td>
<td><span class="style12"><% If(AHTDirSum.Fields.Item("AHT").Value) < (AHTDirSum.Fields.Item("Goal").Value)Then
Response.Write"<td bgcolor= green >"
Else
Response.Write "<td bgcolor= red >" End If %></span></td> <td><span class="style12"><%= FormatNumber((AHTDirSum.Fields.Item("Talk Time").Value), 2, -2, -2, -2) %></span></td>
<td><span class="style12"><%= FormatNumber((AHTDirSum.Fields.Item("Wrap Time").Value), 2, -2, -2, -2) %></span></td>
<td><span class="style12"><%= FormatNumber((AHTDirSum.Fields.Item("Hold Time").Value), 2, -2, -2, -2) %></span></td>
<td><span class="style12"><%= FormatNumber((AHTDirSum.Fields.Item("Goal").Value), 0, -2, -2, -2) %></span></td>
<td><span class="style12"><%= FormatNumber((AHTDirSum.Fields.Item("Variance").Value), 2, -2, -2, -2) %></span></td>
</tr>
russell
01-07-2007, 06:09 PM
psot the entire script. i'll try to show u how to clean it up
Chamark
01-07-2007, 06:31 PM
Thank you russell
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/MetricsCONN.asp" -->
<%
Dim AHTDirSum__MMColParam1
AHTDirSum__MMColParam1 = "1"
If (Request.Form("StartDate") <> "") Then
AHTDirSum__MMColParam1 = Request.Form("StartDate")
End If
%>
<%
Dim AHTDirSum__MMColParam2
AHTDirSum__MMColParam2 = "1"
If (Request.Form("EndDate") <> "") Then
AHTDirSum__MMColParam2 = Request.Form("EndDate")
End If
%>
<%
Dim AHTDirSum
Dim AHTDirSum_cmd
Dim AHTDirSum_numRows
Set AHTDirSum_cmd = Server.CreateObject ("ADODB.Command")
AHTDirSum_cmd.ActiveConnection = MM_MetricsCONN_STRING
AHTDirSum_cmd.CommandText = "SELECT TOP 10000 dbo.[National Call Stats].Director, dbo.[National Call Stats].Segment, SUM(dbo.[National Call Stats].NchQty) AS Calls, SUM(dbo.[National Call Stats].TotalHandleTime) / SUM(dbo.[National Call Stats].NchQty) AS AHT, SUM(dbo.[National Call Stats].[Talk Secs Qty]) / SUM(dbo.[National Call Stats].NchQty) AS [Talk Time], SUM(dbo.[National Call Stats].[Call Wrap Secs Qty]) / SUM(dbo.[National Call Stats].NchQty) AS [Wrap Time], SUM(dbo.[National Call Stats].HoldSecsQty) / SUM(dbo.[National Call Stats].NchQty) AS [Hold Time], dbo.[AHTGoals-DIRGM].Goal, dbo.[AHTGoals-DIRGM].Goal - SUM(dbo.[National Call Stats].TotalHandleTime) / SUM(dbo.[National Call Stats].NchQty) AS Variance FROM dbo.[National Call Stats] INNER JOIN dbo.[AHTGoals-DIRGM] ON dbo.[National Call Stats].Segment = dbo.[AHTGoals-DIRGM].Segment WHERE (dbo.[National Call Stats].[Date] >= ?) AND (dbo.[National Call Stats].[Date] <= ?) AND (dbo.[National Call Stats].Site = N'Dallas') GROUP BY dbo.[National Call Stats].Segment, dbo.[National Call Stats].Segment, dbo.[AHTGoals-DIRGM].Goal, dbo.[National Call Stats].Director HAVING (SUM(dbo.[National Call Stats].NchQty) > 0) ORDER BY dbo.[National Call Stats].Director, dbo.[National Call Stats].Segment"
AHTDirSum_cmd.Prepared = true
AHTDirSum_cmd.Parameters.Append AHTDirSum_cmd.CreateParameter("param1", 200, 1, 255, AHTDirSum__MMColParam1) ' adVarChar
AHTDirSum_cmd.Parameters.Append AHTDirSum_cmd.CreateParameter("param2", 200, 1, 255, AHTDirSum__MMColParam2) ' adVarChar
Set AHTDirSum = AHTDirSum_cmd.Execute
AHTDirSum_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index