Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid cell conditional formatting

Status
Not open for further replies.

MMIMadness

Technical User
Feb 10, 2004
50
GB
I have a datagrid returning a set of values and I want to change the CSS value of a cell based on the value of another value returned in the query. The only way I’ve managed to do it so far is to include the reference value as a column displayed on the final data grid and use the following code to change the values:

Code:
Protected Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            If e.Row.Cells(6).Text = "1" Then
                e.Row.Cells(1).CssClass = "up"
            else
                e.Row.Cells(1).CssClass = "down"
            End If

        End If
    End Sub
But I don’t want the viewer to see the referance value.

If anyone has any ideas on how this couls be done or can point me in the direction of some examples I would be most gratful.

Many thanks,

MMIMadness
 
Don't have a column to display the value that determines the class, play around with e.Row.DataItem instead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top