Datagrid - Changing row colour

S

Simon Harris

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.
 
E

Eliyahu Goldin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top