DataGrid problem

Discussion in 'ASP .Net' started by JL, Dec 30, 2003.

  1. JL

    JL Guest

    Hi all,


    I want to highlight the date overdue row in datagid so that it will be easy
    for user caution, how to change the specific row background color in
    datagrid?


    Thx a lot
    JL, Dec 30, 2003
    #1
    1. Advertising

  2. JL

    George Durzi Guest

    dgMyDataGrid.Items[somenumber].Row.Color

    or something like that ...

    Sorry, no access to VS right now to verify...

    "JL" <> wrote in message
    news:%...
    > Hi all,
    >
    >
    > I want to highlight the date overdue row in datagid so that it will be

    easy
    > for user caution, how to change the specific row background color in
    > datagrid?
    >
    >
    > Thx a lot
    >
    >
    George Durzi, Dec 31, 2003
    #2
    1. Advertising

  3. Hi JL,

    You can catch the ItemDataBound event as each row is getting its data and
    make some decisions there.

    For example, in the code below, I look for the value of "4" in the first
    cell. If I find it, I turn that cell and another red.

    Private Sub Page_Load _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles MyBase.Load
    If Not IsPostBack Then
    DataGrid1.DataSource = CreateDataSource()
    DataGrid1.DataBind()
    End If
    End Sub
    Private Sub DataGrid1_ItemDataBound _
    (ByVal sender As Object, ByVal e As _
    System.Web.UI.WebControls.DataGridItemEventArgs) _
    Handles DataGrid1.ItemDataBound
    If e.Item.ItemType = ListItemType.Item Or _
    e.Item.ItemType = ListItemType.AlternatingItem Then
    If e.Item.Cells(0).Text = "4" Then
    e.Item.Cells(0).BackColor = Color.Red
    e.Item.Cells(3).BackColor = Color.Red
    End If
    End If
    End Sub
    Function CreateDataSource() As ICollection
    Dim dt As New DataTable
    Dim dr As DataRow
    dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
    dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
    dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
    dt.Columns.Add(New DataColumn("Boolean", GetType(Boolean)))
    Dim i As Integer
    For i = 0 To 8
    dr = dt.NewRow()
    dr(0) = i
    dr(1) = "Item " + i.ToString()
    dr(2) = 1.23 * (i + 1)
    dr(3) = True
    dt.Rows.Add(dr)
    Next i
    Dim dv As New DataView(dt)
    Return dv
    End Function 'CreateDataSource

    "JL" <> wrote in message
    news:%...
    > Hi all,
    >
    >
    > I want to highlight the date overdue row in datagid so that it will be
    > easy
    > for user caution, how to change the specific row background color in
    > datagrid?
    >
    >
    > Thx a lot
    >
    >
    Ken Cox [Microsoft MVP], Dec 31, 2003
    #3
    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. sajvargs
    Replies:
    0
    Views:
    378
    sajvargs
    Feb 20, 2005
  2. DC
    Replies:
    2
    Views:
    612
  3. Andreas Klemt
    Replies:
    0
    Views:
    295
    Andreas Klemt
    Oct 8, 2003
  4. roberto
    Replies:
    1
    Views:
    223
    roberto
    Feb 17, 2005
  5. John Walsch
    Replies:
    0
    Views:
    197
    John Walsch
    Jul 9, 2004
Loading...

Share This Page