Hi, I'm trying to get some rows to alternate colors, but it's just not working properly. I am displaying 3 questions along with the answers to each of those questions. On the first question that it builds it alternates rows correctly, on the second question it has ghostwhite for the first 2 rows, the other color for the 3rd and ghostwhite for the 4th. Then when it builds the 3rd question it has ghostwhite for both rows. I was wondering if maybe someone could look over my code and tell me what I'm doing wrong?
I would really appreciate any help you could offer!
VB.NET:
Private Sub strengths()
AnswerQuestion("SELECT strengths FROM tbl_Alumni_Survey_data", _
"1. Based on your experiences at Southside, please indicate what you think our strengths are.", "strengths")
End Sub
Private Sub challenges()
AnswerQuestion("SELECT challenges FROM tbl_Alumni_Survey_data", _
"2. Based on your experiences at Southside, please indicate what you think our challenges are.", "challenges")
End Sub
Private Sub finalComments()
AnswerQuestion("SELECT finalCom FROM tbl_Alumni_Survey_data", _
"3. If there are any further comments you would like to make about Southside, please make them here.", "finalCom")
End Sub
Sub AnswerQuestion(ByVal Query As String, ByVal QName As String, ByVal fieldName As String)
Dim Myconn As SqlConnection
Dim Mycomm As SqlCommand
Dim sql As String
Dim dtr As SqlDataReader
Myconn = New SqlConnection(ConfigurationSettings.AppSettings("gDataSource"))
Myconn.Open()
'begin table/write question
vHTML.Append("<table cellpadding=""3"" cellspacing=""1"" width=""100%"" align=""center"">")
vHTML.Append("<tr bgcolor=""#8B96B1"">")
vHTML.Append("<th colspan=""9"" valign=""bottom"" align=""left"">")
vHTML.Append("<FONT face=""Verdana"" size=""2"" align=""center"">" & QName & "</FONT>")
vHTML.Append("</th>")
vHTML.Append("</tr>")
vHTML.Append("<tr bgcolor=""#E5E5E5"">")
vHTML.Append("<td colspan=""9""> </td>")
vHTML.Append("</tr>")
Dim vComment, row_num, row_bgcolor
Mycomm = New SqlCommand(Query, Myconn)
dtr = Mycomm.ExecuteReader()
Try
If dtr.HasRows Then
While dtr.Read()
row_num = row_num + 1
If ((row_num Mod 2) = 0) Then
row_bgcolor = "ghostwhite"
Else
row_bgcolor = "#E5E5E5"
End If
If dtr(fieldName) = "No comments provided." Then
Else
vHTML.Append("<tr bgcolor='" & row_bgcolor & "' >")
vHTML.Append("<TD colspan=""9"" align=""left""><FONT face=""Verdana"" width=""11%"" size=""1"">" & dtr(fieldName) & "</FONT></TD>")
End If
End While
Else
End If
Catch
End Try
'close table
vHTML.Append("</tr>")
vHTML.Append("<tr bgcolor=""#E5E5E5"">")
vHTML.Append("<td colspan=""9"" valign=""bottom"" align=""left"">")
vHTML.Append(" </td>")
vHTML.Append("</tr>")
vHTML.Append("<tr bgcolor=""#8B96B1"">")
vHTML.Append("<td colspan=""9"" valign=""bottom"" align=""left"">")
vHTML.Append(" </td>")
vHTML.Append("</tr>")
vHTML.Append("</table>")
vHTML.Append("<br/>")
dtr.Close()
Myconn.Close()
lblResults.Text = vHTML.ToString()
End Sub
I would really appreciate any help you could offer!