asp.net, how to change text color to red in child nodes in VB codes?
Posted
by
StudentIT
on Stack Overflow
See other posts from Stack Overflow
or by StudentIT
Published on 2013-11-04T15:25:36Z
Indexed on
2013/11/04
15:54 UTC
Read the original article
Hit count: 376
I got everything worked now by list of server Name but I want to add a IF statement by checking a column from SQL Server called Compliance by either True or False value listed. If it False, the Name will change text color to Red. If it True, the Name won't change text color. I am not sure how add that in VB codes side. I am pretty sure that I would need to put IF statement inside While dr.Read(). I am pretty new to VB.Net and not sure which VB code that change text color.
Here is my VB codes,
Sub loadData()
'clear treeview control
TreeViewGroups.Nodes.Clear()
'fetch owner data and save to in memory table
Dim sqlConn As New System.Data.SqlClient.SqlConnection((ConfigurationManager.ConnectionStrings("SOCT").ConnectionString))
Dim strSqlSecondary As String = "SELECT [Name] FROM [dbo].[ServerOwners] where SecondaryOwner like @uid order by [name]"
'Getting a list of True or False from Compliance column
Dim strSqlCompliance As String = "SELECT [Compliance] FROM [dbo].[ServerOwners] where SecondaryOwner like @uid order by [name]"
Dim cmdSecondary As New System.Data.SqlClient.SqlCommand(strSqlSecondary, sqlConn)
Dim cmdCompliance As New System.Data.SqlClient.SqlCommand(strSqlCompliance, sqlConn)
cmdSecondary.Parameters.AddWithValue("@uid", TNN.NEAt.GetUserID())
cmdCompliance.Parameters.AddWithValue("@uid", TNN.NEAt.GetUserID())
Dim dr As System.Data.SqlClient.SqlDataReader
Try
sqlConn.Open()
Dim root As TreeNode
Dim rootNode As TreeNode
Dim firstNode As Integer = 0
'Load Primary Owner Node
'Create RootTreeNode
dr = cmdSecondary.ExecuteReader()
If dr.HasRows Then
'Load Secondary Owner Node
'Create RootTreeNode
root = New TreeNode("Secondary Owner", "Secondary Owner")
TreeViewGroups.Nodes.Add(root)
root.SelectAction = TreeNodeSelectAction.None
rootNode = TreeViewGroups.Nodes(firstNode)
'populate the child nodes
While dr.Read()
Dim child As TreeNode = New TreeNode(dr("Name"), dr("Name"))
rootNode.ChildNodes.Add(child)
child.SelectAction = TreeNodeSelectAction.None
End While
dr.Close()
cmdSecondary.Dispose()
End If
'check if treeview has nodes
If TreeViewGroups.Nodes.Count = 0 Then
noServers()
End If
Catch ex As Exception
hide()
PanelError.Visible = True
LabelError.Text = ex.ToString()
Finally
sqlConn.Dispose()
End Try
End Sub
© Stack Overflow or respective owner