Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Condition Formatting on GridView

Reply
Thread Tools

Condition Formatting on GridView

 
 
Jim in Arizona
Guest
Posts: n/a
 
      08-16-2006
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
 
Reply With Quote
 
 
 
 
David Wier
Guest
Posts: n/a
 
      08-17-2006
Check out this code sample at ASPNet101.com:
http://aspnet101.com/aspnet101/aspne...de=gvcellcolor

David Wier
MVP/ASPInsider
http://aspnet101.com
http://aspexpress.com

"Jim in Arizona" <(E-Mail Removed)> wrote in message
news:%23Kv$(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
Jim in Arizona
Guest
Posts: n/a
 
      08-17-2006
David Wier wrote:
> Check out this code sample at ASPNet101.com:
> http://aspnet101.com/aspnet101/aspne...de=gvcellcolor
>
> David Wier
> MVP/ASPInsider
> http://aspnet101.com
> http://aspexpress.com
>


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.CloseConn ection)
gvData.DataBind()
If objConnection.State = ConnectionState.Open Then
objConnection.Close()
End If

End Sub
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with while condition OR condition Bill W. Ruby 13 05-09-2011 09:42 PM
GRIDVIEW: condition processing =?Utf-8?B?TWFya0F1cml0?= ASP .Net 1 02-07-2007 11:39 PM
Editable/Uneditable Gridview rows on condition Mike P ASP .Net 3 06-06-2006 03:48 PM
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= ASP .Net 1 05-09-2006 06:48 PM
Condition outside loop or separate loop for different condition? - Java 12 06-15-2005 08:50 AM



Advertisments