473,569 Members | 2,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid - Changing row colour

Hi All,

Ok, I have 6 datagrids, populated from 1 dataset. Each datagrid has 3
columns. There are 18 columns in the dataset.

I have written a sub to change the background colour of the row in the
datagrid, if the current rows 'booked' column value = 'yes'

Here is my code:

Public Sub CheckAvailabili ty(ByVal sender As Object, ByVal e As
DataGridItemEve ntArgs)
If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType =
ListItemType.Al ternatingItem Then
Dim strBooked As String = DataBinder.Eval (e.Item.DataIte m,
"Booked").ToStr ing()
If strBooked.ToLow er = "yes" Then
e.Item.CssClass = "tariffsDGBooke d"
End If
End If
End Sub

This works fine, but I actually need a 'booked' column for each datagrid -
ie. booked1, booked2...upto. ..booked6

I have added this to my data, and added the relevent booked column to each
datagrid, what I now need to do is change my sub so that it looks for the
correctly named 'booked' column (Obviously looking for 'booked' each time
isnt going to work. This is where I am stuck! I was thinking perhaps using
eventargs to send the datagrid id to the sub (I know the ID will match the
bookedX column name). I'm just not sure a) How to do this and B) is this the
right approach?

Hope someone has a suggestion! :)

Regards,
Simon.

Nov 19 '05 #1
1 1202
Simon,

Is CheckAvailabili ty a datagrid ItemDataBound event handler? If so,
parameter sender represent the datagrid that originated the event. You just
need to typecast it.

Eliyahu

"Simon Harris" <to***********@ makes-you-fat.com> wrote in message
news:OM******** ******@TK2MSFTN GP10.phx.gbl...
Hi All,

Ok, I have 6 datagrids, populated from 1 dataset. Each datagrid has 3
columns. There are 18 columns in the dataset.

I have written a sub to change the background colour of the row in the
datagrid, if the current rows 'booked' column value = 'yes'

Here is my code:

Public Sub CheckAvailabili ty(ByVal sender As Object, ByVal e As
DataGridItemEve ntArgs)
If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType =
ListItemType.Al ternatingItem Then
Dim strBooked As String = DataBinder.Eval (e.Item.DataIte m,
"Booked").ToStr ing()
If strBooked.ToLow er = "yes" Then
e.Item.CssClass = "tariffsDGBooke d"
End If
End If
End Sub

This works fine, but I actually need a 'booked' column for each datagrid -
ie. booked1, booked2...upto. ..booked6

I have added this to my data, and added the relevent booked column to each
datagrid, what I now need to do is change my sub so that it looks for the
correctly named 'booked' column (Obviously looking for 'booked' each time
isnt going to work. This is where I am stuck! I was thinking perhaps using
eventargs to send the datagrid id to the sub (I know the ID will match the
bookedX column name). I'm just not sure a) How to do this and B) is this the right approach?

Hope someone has a suggestion! :)

Regards,
Simon.

Nov 19 '05 #2

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

Similar topics

0
1617
by: ZaGras | last post by:
does anybody know make the column in the datagrid with different background colour, meaning that column1 is blue in colour, column2 is yellow in colour..?
1
1456
by: JD | last post by:
How do i get rid of the 1st column that appears in a datagrid? I do not want this? Also how do i change the colour of the background of a cell when the user selects it. i.e for the first coloumn i have made this non-editable and therefore i do not want the graey colour that appears when the user clicks on a cell in the first row. As only...
0
1135
by: Oldhandandy | last post by:
I'm trying to create a multiply table (SQL) datagrid which updates fields in the primary table. The primary table holds diluted information such as a colour id, e.g. colour id for black is 5, on the datagrid it must show BLACK. In this case the primary table is linked to the colour table to get the actual colour. When I configure the dataset I...
1
3332
by: Leo | last post by:
Can someone tell me how to make the sorting triangle on datagrid column header always show up? And which property can change the color of the triangle ? The default color is white. Thanks
0
1016
by: gerry.brennan | last post by:
Hi, Does anyone know if it is possible to turn just "Vertical gridlines" a different colour in a datagrid. Gerry.
1
1810
by: Anup | last post by:
Hi group, I m using protected System.Web.UI.WebControls.DataGrid (ASP.NET 1.x) I have set the "pager style mode" to "NumericPages" with "AllowingPaging=true"
1
1499
by: Steve | last post by:
C# WinForms I am trying to find a good solution for changing the color of a row in a datagrid, at runtime, based on the contents of a certain cell of the row, or a related value in the database. I cant believe it is as hard as I am finding. This is surely a common problem. All the solutions I have found so far though, seem very...
0
1331
by: satish | last post by:
I have a table with two columns field1 int,Field2 and added a column to datagrid on runtime sum (field1+field2) ,upon changing the data in either of the fileds the sum field or column too changes . Intially there will be data in the fields ..and ii try to change the value of column so the column also changes,Can i change the colour of the...
1
1655
by: satish | last post by:
I have a table with two columns field1 int,Field2 and added a column to datagrid on runtime sum (field1+field2) ,upon changing the data in either of the fileds the sum field or column too changes . Intially there will be data in the fields ..and ii try to change the value of column so the column also changes,Can i change the colour of the...
0
7612
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...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7673
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...
0
7970
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
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...
1
5513
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...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
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
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.