473,804 Members | 4,795 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Condition Formatting on GridView

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
Aug 16 '06 #1
2 5317
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" <ti*******@hotm ail.comwrote in message
news:%2******** *******@TK2MSFT NGP05.phx.gbl.. .
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

Aug 17 '06 #2
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 GridViewRowEven tArgs)
If e.Row.RowType = DataControlRowT ype.DataRow Then
If e.Row.Cells(10) .Text "44" Then
e.Row.BackColor = Drawing.Color.L ightYellow
e.Row.Cells(10) .ForeColor = Drawing.Color.R ed
e.Row.Cells(10) .Font.Bold = True
End If
If e.Row.Cells(11) .Text "59" Then
e.Row.BackColor = Drawing.Color.L ightYellow
e.Row.Cells(11) .ForeColor = Drawing.Color.R ed
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.EventArg s) Handles btnSubmit.Click

objConnection.O pen()
gvData.DataSour ce =
objCommand.Exec uteReader(Comma ndBehavior.Clos eConnection)
gvData.DataBind ()
If objConnection.S tate = ConnectionState .Open Then
objConnection.C lose()
End If

End Sub
Aug 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6224
by: washoetech | last post by:
I have a gridview control. In this grid view there is a column for the price of an item. Some of the prices have a dollar sign in front of it and some dont. How do I get rid of the dollar sign if it is in front of the value? My guess would be to use a template column but I dont know how to go about this. Any ideas? Below is an example of what the data looks like raw from the database: $456.95 200.89
1
4581
by: euan | last post by:
HI Guys, I have bee using conditional formatting in the datagrid recently and I am moving over to framework 2.0 and noticed the datagrid has been replaced by the gridview. So, I would like to do conditional formatting on the gridview but it doesnt have the same methods. Currently in my datagrid I have this (this is just hacked together randomly but gives you the idea):
4
2621
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I re-format the updated row fields. I have looked at gridView.rowUpdated method, but cannot figure out how....
3
2098
by: Simon Harvey | last post by:
Hi all, I'm having problems getting my date to format. Someone told me that with the GridView, you need to use a TemplateColumn and not a BoundColumn when displaying dates. Given that, can anyone see what the problem is with the following code.... <asp:TemplateField HeaderText="Departure Date"> <ItemTemplate>
3
2403
by: CSharpguy | last post by:
I'm trying to format the GridView on my web form and its not working. for money I have {0:C} and for date fields, I have {0:d} and the format isn't changing, what else do I need to do to get the formatting working in the gridView?
4
8338
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the date column always shows the date and time while I just want the short date. I have tried applying a format string {0:d} but to no avail. I saw a lot of posts regarding the htmlencode property but I do not know how to turn that off for a...
1
1875
by: AmitKu | last post by:
I've got the Gridview going at full speed, and I've enabled editing, but when I click on the "edit" button, this ugly editing UI comes up. Well it's not ugly, but it's not great either. How do I change the font/font size of the text thats being edited? Thanks in advance, Amit
2
2091
by: pgonzo | last post by:
In my initial tests with the GridView control, I cannot understand why the DataFormatString attribute has no affect on the column formatting. The 'creation_date' field is being reported as "3/30/02 14:23:28". I want to display it as "03/30/02". I've included the code below. Can anyone offer an explanation? <asp:SqlDataSource ID="DD_Issues" runat="server"
2
2422
by: tomh2099 | last post by:
Hi, Hi, I have an ASP.NET 2005 application (using VB) with a GridView control that needs to have the last 5 or 6 rows in Bold or maybe some other special formatting. Most of the rows show monthly info but the last few show other information. The gridview is bound to a stored procedure that returns data something like this: 'Jan 2007', 0 'Feb 2007', 8
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10320
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9150
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.