Thanks for bringing this up. There are actually several problems with the original "if" statement's expression. Checking the ItemTemplate is arbitrary and wrong. This was pointed out to me previously. It is perfectly OK to create a FormView that is always shown in edit mode. In such cases, the FormView has just the EditItemTemplate, not the ItemTemplate, defined. So checking for the existance of the ItemTemplate is simply wrong.
Whoops. My bad.
I like your solution but I'd like to modify just a little to be:
C#
if (IsFormView &&
(ControlAsFormView.Row != null) &&
(ControlAsFormView.Row.Cells.Count > 0) &&
(ControlAsFormView.Row.Cells[0].Controls.Count > 0))
VB
If (IsFormView AndAlso _
(Not IsNothing(ControlAsFormView.Row)) AndAlso _
(ControlAsFormView.Row.Cells.Count > 0) AndAlso _
(ControlAsFormView.Row.Cells.Item(0).Controls.Count > 0)) Then
This is a bit safer and drops the clause that wrongly checked ItemTemplate.
What do you think?
Russ Helfand
Groovybits.com