Conditional formatting of nested gridview cells

Discussion in 'ASP .Net' started by Nitz, Mar 25, 2009.

  1. Nitz

    Nitz Guest

    Hi,

    How can i change the forecolor/backcolor of a cell in a nested gridview
    based on the content of the cell ?

    It's easy to do it with the master gridview with the rowdatabound event but
    i have no clue how to do it with nested controls.
    Nitz, Mar 25, 2009
    #1
    1. Advertising

  2. Nitz

    Sam Evans Guest

    Hi Nitz

    It's just an extension of the rowdatabound event. I'm assuming that your
    nested grid is using a value from the out grid as a parameter for stored
    procedure or something similar. My code is below

    Protected Sub gvRange_RowDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvRange.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then
    Dim s As SqlDataSource =
    CType(e.Row.FindControl("dsRangeInner"), SqlDataSource)
    s.SelectParameters(2).DefaultValue = e.Row.Cells(1).Text
    counter += 1
    Dim gvOrders As GridView = CType(e.Row.FindControl("gvOrders"),
    GridView)
    gvOrders.DataBind()
    Dim row As GridViewRow
    For Each row In gvOrders.Rows
    If row.RowType = DataControlRowType.DataRow Then
    Dim chkAvailable As CheckBox =
    CType(row.FindControl,"chkAvailable"), CheckBox)
    Dim chkPlanned As CheckBox =
    CType(row.FindControl("chkPlanned"), CheckBox)
    If Not (chkPlanned.Checked Or chkOilAvailable.Checked)
    Then
    row.Cells(0).ForeColor = Drawing.Color.Red
    End If

    End If

    Next

    End If
    End Sub

    For each row in the outer grid, I pick up the gridview in the template, make
    sure I do databind on the inner gridview then step through the rows in the
    same way as on the outer gridview, using the values of a couple of checkboxes
    to decide the format of my order number column. I hope I've explained that
    well enough, it sounds a bit garbled to me, but should be easy enough to
    follow.

    "Nitz" wrote:

    > Hi,
    >
    > How can i change the forecolor/backcolor of a cell in a nested gridview
    > based on the content of the cell ?
    >
    > It's easy to do it with the master gridview with the rowdatabound event but
    > i have no clue how to do it with nested controls.
    >
    Sam Evans, Apr 6, 2009
    #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. Replies:
    2
    Views:
    4,575
  2. Replies:
    2
    Views:
    10,418
    FatherJ
    Oct 29, 2007
  3. Not Me

    Gridview - conditional formatting

    Not Me, Feb 9, 2006, in forum: ASP .Net
    Replies:
    9
    Views:
    6,808
    code_monkey
    Nov 8, 2006
  4. Indo77
    Replies:
    0
    Views:
    980
    Indo77
    Oct 8, 2007
  5. Saverio Tedeschi

    Cells conditional formatting (i.e.Red for negative values)

    Saverio Tedeschi, Feb 28, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    5
    Views:
    174
    mkhmer
    Mar 9, 2006
Loading...

Share This Page