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:

Code:
<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:

Code:
  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.
 

MattP

Well-known member
Joined
Feb 29, 2008
Messages
1,206
Location
WY, USA
Programming Experience
5-10
Try something like this:

Code:
Dim _lblStartingDate As Label = Me.DetailsView2.FindControl("lblStartingDate")
 
Top Bottom