There doesn,t appear to be alot of good references for dynamically evaluating column values on a Gridview and changing the row color based on criteria. I am a big advocate of this .net tutorial: http://asp.net/learn/data-access/tutorial-11-vb.aspx. But this tutorial suggests making a database call on every row that is bound, simply to evaluate if you want to highlight the row. This does not make much sense as the information as everything you need exists in the RowDataBound event. The row can be highlighted using just 3 lines of code on the RowDataBound event:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If Trim(e.Row.Cells(7).Text) <> "MyText" And Trim(e.Row.Cells(7).Text) <> "HeaderText" Then
e.Row.BackColor = Color.Orange
End If
End Sub
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment