Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

findcontrol

Status
Not open for further replies.

Dimitrie1

Programmer
Jan 5, 2007
138
CA
I want to switch font colours depending on a value - this code works great when the form loads but errors on the lbl.ForeColor = Drawing.Color.Red
when I try to update - it doesn't seem to find the label

Protected Sub GridView3_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView3.RowCreated

If e.Row.RowType = DataControlRowType.DataRow Then
Dim lbl As Label = CType(e.Row.FindControl("Label1"), Label)

If DataBinder.Eval(e.Row.DataItem, "Over_Under") < 0D Then
lbl.ForeColor = Drawing.Color.Red
Else
lbl.ForeColor = Drawing.Color.Blue
End If
End If

End Sub
 
When you are updating, are you not in the EditItem mode? does that label exist for that row at that point?

if not... change that statement to include if rowtype is not edited.... with a datagrid its like

if not e.Item.ItemType = listItemType.EditItem then
....

not sure about gridview.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top