Datagrid - Changing row colour

Discussion in 'ASP .Net' started by Simon Harris, Feb 9, 2005.

  1. Simon Harris

    Simon Harris Guest

    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.
    Simon Harris, Feb 9, 2005
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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.
    >
    >
    >
    Eliyahu Goldin, Feb 10, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt B
    Replies:
    4
    Views:
    783
    Matt B
    Oct 11, 2005
  2. Phil Johnson

    Datagrid - set row colour in code

    Phil Johnson, Mar 11, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    437
    Phil Johnson
    Mar 11, 2008
  3. D
    Replies:
    0
    Views:
    199
  4. Alternate row colour

    , Dec 9, 2005, in forum: Javascript
    Replies:
    4
    Views:
    97
  5. jodleren
    Replies:
    2
    Views:
    188
    Thomas 'PointedEars' Lahn
    Jan 12, 2008
Loading...

Share This Page