Conditional formatting of nested gridview cells

N

Nitz

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

Sam Evans

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.
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top