How to change colors of gridview from sql data

mr_evans2u

New member
Joined
Oct 2, 2012
Messages
2
Programming Experience
5-10
I need to change the colors of the rows depending on what I get in the OU field from sql.
I am getting the information here, which works fine as is

VB.NET:
Dim strSQL As String = "SELECT TOP 250 Name, ProxyAddress, mail, OU FROM ProxyLookup WHERE ProxyAddress LIKE '%" & txtProxyAddr.Text & "%'"
                ViewState("dtSearchResults") = sqlConn.getDataTable(strSQL.ToString)
                GV.DataSource = ViewState("dtSearchResults")
                GV.DataBind()
                lblGVMsg.Text = CType(ViewState("dtSearchResults"), DataTable).Rows.Count & " record(s) found"
                lblGVMsg.ForeColor = Drawing.Color.Black

The OU table can show one of the following data strings. If the OU is equal to Contacts those rows get a certain color, if OU is equal to Distrubution Lists those rows get a different color, etc...
OU=External,OU=Contacts,OU=Accounts,DC=us,DC=xxx,DC=comapnay,DC=com
OU=AD,OU=Distribution Lists,DC=us,DC=xxx,DC=company,DC=com
OU=$Generic Accounts,OU=Mailboxes,OU=Accounts,DC=us,DC=xxx,DC=company,DC=com



Any help is appriciated,
Thank you in advance
 
figured it out

VB.NET:
If Not e.Row.DataItem Is Nothing Then
            Dim drv As DataRowView = CType(e.Row.DataItem, DataRowView)
            Dim catName As String = Convert.ToString(drv("OU"))
If catName.Split(",")(1).Trim = "OU=Contacts" Or catName.Split(",")(2).Trim = "OU=Contacts" Then
                e.Row.BackColor = System.Drawing.Color.Yellow
End If
        End If
 
Back
Top