Question Detailsview If statement for field values

jamie1984

New member
Joined
Jul 29, 2008
Messages
1
Programming Experience
1-3
hi

I have a detailsview with a template field in, e.g:

VB.NET:
<asp:TemplateField HeaderText="Starting Date">
  <ItemTemplate>
       <asp:Label ID="lblStartingDate" runat="server" 
       Text='<%# Bind("[Starting Date]", "{0:dd/MM/yyyy}") %>'></asp:Label>
  </ItemTemplate>
</asp:TemplateField>

What I would like to do is if the date is less than "01/01/2000" then hide the label.

I have tried to achieve this through code behind by finding the control, e.g:

VB.NET:
  lblstartingdate = DirectCast(Me.DetailsView2.FindControl("lblStartingDate"), Label)
        If lblstartingdate.Text < "01/01/2000" Then
         lblstartingdate.Visible = False
         End if

but I receive a "Object reference not set to an instance of an object" error.

any advice on the best way to achieve this?

thanks.
 
Try something like this:

VB.NET:
Dim _lblStartingDate As Label = Me.DetailsView2.FindControl("lblStartingDate")
 
Back
Top