473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 CheckAvailability(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim strBooked As String = DataBinder.Eval(e.Item.DataItem,
"Booked").ToString()
If strBooked.ToLower = "yes" Then
e.Item.CssClass = "tariffsDGBooked"
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 1190
Simon,

Is CheckAvailability 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**************@TK2MSFTNGP10.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 CheckAvailability(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim strBooked As String = DataBinder.Eval(e.Item.DataItem,
"Booked").ToString()
If strBooked.ToLower = "yes" Then
e.Item.CssClass = "tariffsDGBooked"
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
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
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...
0
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...
1
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
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
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
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....
0
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 ....
1
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 ....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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,...

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.