Condition Formatting on GridView

J

Jim in Arizona

Using a GridView or other data reading control (gridview, datagrid,
datalist), how can I do conditional formatting on the results pulled
from an access database? As an exampe, use a sql statement to bind to
the datagrid, and one of the columns has numerical data. How would I,
say, make any data in that column that is over 1000 to be in red or bold?

If this can't be done using one of these controls, how else would I get
the job done?

Sometimes I feel I'm over my head, but, it's good to know these groups
exist.

TIA,
Jim
 
J

Jim in Arizona

David said:

The example you pointed me to worked like a charm. Thanks for your help!

Here's my code in case anyone is curious.

In the aspx file:

<asp:GridView ID="gvData" runat="server" OnRowDataBound="doColor">

In the aspx.vb file (the btnSubmit sub is cut down for space):

Sub doColor(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(10).Text > "44" Then
e.Row.BackColor = Drawing.Color.LightYellow
e.Row.Cells(10).ForeColor = Drawing.Color.Red
e.Row.Cells(10).Font.Bold = True
End If
If e.Row.Cells(11).Text > "59" Then
e.Row.BackColor = Drawing.Color.LightYellow
e.Row.Cells(11).ForeColor = Drawing.Color.Red
e.Row.Cells(11).Font.Bold = True
End If
End If
End Sub

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click

objConnection.Open()
gvData.DataSource =
objCommand.ExecuteReader(CommandBehavior.CloseConnection)
gvData.DataBind()
If objConnection.State = ConnectionState.Open Then
objConnection.Close()
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top