An approach I've taken to achieve this type of formatting with a datagrid
was to:
1. Bind data source to datagrid
2. Examine content of datagrid in a loop and apply style classes from the
css stylesheet.
I don't think it's possible to do both at the same time as you desire, but
both of the above actions will occur before the user gets to see the
results, so from a user experience perspective it would sem as if they are
occurring simultaneously.
Note that the custom styling required that I first remove any style applied
using the datagrid designer, because these add background colour statements
instead of being stylesheet class based and as such override style class
statements.
Having done that, you can then go to the code behind. After the method for
puling your data occurs and the list is databound, call the second method to
apply the custom highlighting, something like the following:
'#########
private subPage_Load()
'...
If not me.page.IsPostback then
'...
me.LoadDataGrid()
me.SetHighlight()
'...
end if
end sub
private sub LoadGridData()
'Connect to db, get data values.
'...
me.dgOuter.datasource = mySourceDataset
me.dgOuter.databind
'...
end sub
Private Sub SetHighlight()
Dim i As Integer
For i = 0 To Me.dgOuter.Items.Count - 1
If Me.dgOuter.Items.Item(i).Cells(1).Text = "TX" Then
Me.dgOuter.Items.Item(i).CssClass = "myTexasHighlightStyle"
End If
Next
End Sub
'#########
I've always used the datagrid by preference. However, there are some
features of the datalist that should support a similar approach to the
above, perhaps something like this:
Private Sub SetDataListHighlight()
Dim state As Label
For i = 0 To Me.DataList1.Items.Count - 1
state = Me.DataList1.FindControl("lblState")
If state.Text = "TX" Then
'Need to set the row style
Me.DataList1.Items.Item(i).CssClass = "myTexasHighlightStyle"
End If
Next
End Sub
Hope that helps.
Al