473,480 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Data Grid Question

I'm trying to use a datagrid to display data and that has been easy - what
i'm trying to do is have a rows background color change to red if the first
databound column is 0 for the item. I have entered an onitemcreated sub
routine to handle the data item when its added to the grid but it hasn't
worked. This is my sub below:

Sub OnCreatedItem(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)

If e.Item.Cells(0).Text = "0" Then
UnitLists.Items(e.Item.ID).BackColor =
System.Drawing.Color.ForestGreen
'e.Item.BackColor = System.Drawing.Color.ForestGreen
End If
End Sub

How do i code this so I can vary the background colors for the cells
depending on the data that it contains?

Thank you for your help,
Ryan
Nov 19 '05 #1
1 1299
u should use datagrid's itemdatabound event instead of using oncreated item
..

because no data is set at item creation stage.. it should works at on
itemdatabound event

One more thing, don't use e.item.cells(0)

use a code like following;
Dim rw as DataRowView = e.item.DataItem
if rw!=null
rw(0).Equals("0")
or something similar this

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET
"Ryan Smith" <Ry*******@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com...
I'm trying to use a datagrid to display data and that has been easy - what
i'm trying to do is have a rows background color change to red if the
first
databound column is 0 for the item. I have entered an onitemcreated sub
routine to handle the data item when its added to the grid but it hasn't
worked. This is my sub below:

Sub OnCreatedItem(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)

If e.Item.Cells(0).Text = "0" Then
UnitLists.Items(e.Item.ID).BackColor =
System.Drawing.Color.ForestGreen
'e.Item.BackColor = System.Drawing.Color.ForestGreen
End If
End Sub

How do i code this so I can vary the background colors for the cells
depending on the data that it contains?

Thank you for your help,
Ryan

Nov 19 '05 #2

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

Similar topics

0
4100
by: Mike N. | last post by:
Hello to all: First let me apologize for the length of this question, I've made an attempt to include as much information as is needed to help with the question. I am having problems putting...
1
1476
by: Ananth | last post by:
Hi, I have a question regarding data grids My application requires me to use a grid for displaying data, however I would not be using a database for procuring the data, instead I would be...
6
3818
by: Hutty | last post by:
I've looked around and have yet to find anything that would answer my question regarding formating a column in a datagrid. My grid looks like this as far as data" AMHQCON|51300.01|-3147 The...
6
1468
by: Paul | last post by:
Hi I have 2 data grids and several controls on a web page. The grids will vary in size, just wondering if the lower grid could be covered by part of the upper grid depending on its size or is there...
2
3824
by: Jack Smith | last post by:
My development environment is ASP.Net with Vb.Net and Java script with .Net Framework 1.1 and IE 6.x. I have a search window and once the user done with search, if user wants to clear the search...
3
2189
by: pmud | last post by:
Hi, I have a web page (asp.net, code:c#). I havean html table with text boxes. Based on the user input , records are displayed in the data grid below it. Now the datagrid has a large no. of...
2
2688
by: Brian Mitchell | last post by:
Ok, I know this is an elementary question but I have a data grid that is bound to a data table and I can't seem to find a way to match the selected row in the grid with it's respective row in the...
4
2459
by: JIM.H. | last post by:
Hello, I am trying to write the data I got from a web service to my table in SQL Server I need to append the dataset wsDS to the dataset ds and do update. PVS.myWS.Loader load = new...
5
1363
by: AAJ | last post by:
Hi all FIRST THE BORING BITS....... I normally use a Database layer, a Business layer and a GUI layer. The GUI uses an Object data source to bind to the Business layer which in turn binds...
3
2166
by: gilbert3b2g | last post by:
I'm new to Python, and programming in general. What I'm trying to do here is to load a list of accounts from a file on my harddrive into a string of Buttons in Tkinter, and when I press one of the...
0
7041
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,...
0
6908
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...
0
7084
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...
1
6739
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...
0
6929
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
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 ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
181
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...

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.