Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Test for Null in a DataList


Message #1 by "Mitchell Adams" <MADAMS@p...> on Fri, 20 Sep 2002 13:02:05 -0400
Does anyone know how can I test for Null at the ItemTemplate level in a 
DataList?

I'd like to do something like:
<ItemTemplate>
<% If IsNull(Containter.DataItem("Address2")) =3D false then Response.Write
(Container.DataItem("Address2") & "<br>") End If %>
</ItemTemplate>


I'd like to avoid calling a function like the one below to solve the 
problem:
  

Public Function NullTest(ByVal FieldValue As Object) As String
        If Not FieldValue IS DBNull.Value Then
		   Return FieldValue.ToString() & "<br>"
        End If
End Function


my code snippet:

<asp:DataList id=3D"dgList" runat=3D"server" CSSClass=3D"Normal_11px">
<ItemTemplate>
<p>
<b><%# Container.DataItem("Name") %></b><br>
<%# Container.DataItem("Address") %><br>
<%# NullTest(Container.DataItem("Address2")) %>
<%# Container.DataItem("City")%>, <%# Container.DataItem("State")%>&nbsp;&n
bsp;<%# Container.DataItem("Zip")%><br>
<%# Container.DataItem("Phone")%><br>
<%# NullTest(Container.DataItem("URL")) %><br><br><br>
</p>
</ItemTemplate>
</asp:DataList>



Thanks

Mitch


  Return to Index