473,666 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change color of GridView row

I have a need to make a GridView row a different color (red) if a date
exists on the row. I assume I would do this in the OnDataBound event. I
know how to make a Cell(x) a different color but not a row. Thanks.

David
Apr 20 '07 #1
2 12393
Theres an example here

http://msdn2.microsoft.com/en-us/library/aa479342.aspx

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog

"David C" <dl*****@lifeti meinc.comwrote in message
news:eY******** ******@TK2MSFTN GP02.phx.gbl...
>I have a need to make a GridView row a different color (red) if a date
exists on the row. I assume I would do this in the OnDataBound event. I
know how to make a Cell(x) a different color but not a row. Thanks.

David

Apr 20 '07 #2
David C wrote:
I have a need to make a GridView row a different color (red) if a date
exists on the row. I assume I would do this in the OnDataBound event. I
know how to make a Cell(x) a different color but not a row. Thanks.

David

Here's some code I put together a while back as an additional example to
John's reply. Watch for wrap!

Sub doColor(ByVal sender As Object, ByVal e As GridViewRowEven tArgs)

Dim test As New BoundColumn()

If e.Row.RowType = DataControlRowT ype.DataRow Then
Dim i9, i10 As Integer

If Int32.TryParse( e.Row.Cells(9). Text, i9) AndAlso i9 >= 45
Then
e.Row.BackColor = Drawing.Color.L ightYellow
e.Row.Cells(9). ForeColor = Drawing.Color.R ed
e.Row.Cells(9). Font.Bold = True
End If

If Int32.TryParse( e.Row.Cells(9). Text, i9) AndAlso i9 < 0 Then
e.Row.BackColor = Drawing.Color.Y ellow
e.Row.Cells(9). ForeColor = Drawing.Color.R ed
e.Row.Cells(9). Font.Bold = True
End If

If Int32.TryParse( e.Row.Cells(10) .Text, i10) AndAlso i10 >=
60 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

End If

End Sub
Apr 20 '07 #3

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

Similar topics

5
1437
by: ~~~ .NET Ed ~~~ | last post by:
Well, maybe not half-baked but 75%. I find very frustrating working with the DataGrid control. It offers a lot of functionality which really comes in handy. Unfortunately you can only enjoy a DataGrid to its fullest when you "drop" it on a web form. There you can modify all sorts of properties for the look and behaviour to your hearts content. But then, when you decide to use the DataGrid as a child control of a web custom composite...
1
5992
by: K B | last post by:
Hi. I have a gridview with sqldatasource, etc. For the grid, I also have a search textbox. If the user needs to filter the records, I want to dynamically adjust the SELECT statement for the SqlDataSource. I like all the automatic capabilities for paging, sorting, etc., so I don't want to just bind the old way. Any clues? thanks, KB
3
3291
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when the field should only be showing one or the other (date or time). Even on the back end of the database where the column properties are, I have chosen the smallest date/time formats. When the aspx page runs, it shows the date and time (ie:in a...
1
4272
by: Sharon | last post by:
Hello All, I have a gridview control in webform which is dynamically populated on page startup with a query. I was trying to change the header text for the columns and also set wrap to false. i have four columns in gridview. Any suggestions guys This is what i used but i keep getting error Private Sub changestyle() GridView1.Columns(1).HeaderText = "First Name"
1
4140
by: gary.comstock | last post by:
We have a non asp web page that contains a hyperlink which opens an iframe. The iframe is hidden until the hyperlink is selected then javascript toggles the visibility to 'visible'. Inside the iframe is our aspx page which contains a gridview. I've manually set the iframe width to larger than the gridview will ever be and have allowtransparency set to 'true' so you really can't see the iframe, just the gridview. As gridview paging...
1
2016
by: =?Utf-8?B?SGFycnkgS2Vjaw==?= | last post by:
I have a GridView control with a few columns declared directly in the aspx file. I have found that if I remove the HeaderText property from all columns that the GridView handles state completely differently than if any of the columns has a value set for HeaderText. This sounds completely wrong to me. Has anyone ever heard of this? When no columns have a HeaderText, the GridView maintains columns similarly to the old DataGrid. If I...
3
7321
by: pvong | last post by:
VB.NET How do you change a gridview from Update mode to normal mode? I'm usually dealing for Formviews and there is a ChangeMode option but I don't see one for Gridviews.
1
2600
by: dhaneshrs | last post by:
I have a small code that shows inactive and active users from the ms access DB. <%@ Page Language="VB" MasterPageFile="~/MasterPageAdmin.master" Title="Welcome" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <%@ Import Namespace="System.Drawing" %> <script language="VB" runat="server"> Public Function GetInActiveDays(ByVal strLastLoginDate As String) As Integer Dim date1 As Date = New...
3
1913
by: Laila2008 | last post by:
Hi, I am trying to update data and highlight updated row in a GridView. To change the data I loop through the dataset, find the row I want, set the new data and call DataBind() on the GridView. To change row color I loop through the GridView, find the row and update color. But this involves 2 loops! Once through the underlying dataset and once through GridView... not clean at all. Any ideas? Thanks!
1
9417
by: Bogdan | last post by:
Hi, I'm using skin and css to style a gridview. I've run into something that seems like a very trivial problem - I can't change color of lines within a gridview. Setting the border color has not affect on the lines. Could someone please let me know how to do that? Thanks, Bogdan
0
8444
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...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
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,...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
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
4198
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
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1775
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.