Solved

Dynamically excluding a row in a data repeater when there's bad data

Posted on 2004-09-08
2
257 Views
Last Modified: 2008-02-01
I have a repeater that doesn't display some info if null is returned in the recordset.  For example, if either the state or city names are  null then that line of the address is omitted.

This works fine, but every now and again I have some bad data.  The word "null" appears as a value in some cases, so I want to not only exclude null values but also "null" literals.

How would I modify the following to accomplish this?
------------------------------------------------------
<asp:TableRow Visible='<%# Not IsDBNull(DataBinder.Eval(Container.DataItem, "CITY")) and Not IsDBNull(DataBinder.Eval(Container.DataItem, "STATE"))%>'>
<asp:TableCell><%# DataBinder.Eval(Container.DataItem, "CITY") %>, <%# DataBinder.Eval(Container.DataItem, "STATE") %> &nbsp;<%# DataBinder.Eval(Container.DataItem, "ZIP") %></asp:TableCell></asp:TableRow>
------------------------------------------------------

The whole code for the repeater is below

Thanks.

Leprechaun

---------------------
<asp:repeater id=Repeater1 runat="server">
<HeaderTemplate>
      <tr><td width=25%><B>Store Name:</B></td><td width=75%><b>Address:</b></td></tr>
</HeaderTemplate>
<ItemTemplate>
      <tr><td width=25% valign=top>
      <table><tr><td valign=top><%# DataBinder.Eval(Container, "ItemIndex") +  1 %>.<br>&nbsp;&nbsp;&nbsp;</td><td valign=top><%# DataBinder.Eval(Container.DataItem, "COMPANY_NAME").ToUpper() %></td></tr></table>
      </td>
      <td width=75% valign=top>
      <asp:table runat="server" ID="Table1" NAME="Table1" BorderWidth=0 CellPadding=0 CellSpacing=0>
            <asp:TableRow Visible='<%# Not IsDBNull(DataBinder.Eval(Container.DataItem, "ADDRESS"))%>'>
                  <asp:TableCell><%# DataBinder.Eval(Container.DataItem, "ADDRESS") %></asp:TableCell></asp:TableRow>
            <asp:TableRow Visible='<%# Not IsDBNull(DataBinder.Eval(Container.DataItem, "CITY")) and Not IsDBNull(DataBinder.Eval(Container.DataItem, "STATE"))%>'>
                  <asp:TableCell><%# DataBinder.Eval(Container.DataItem, "CITY") %>, <%# DataBinder.Eval(Container.DataItem, "STATE") %> &nbsp;<%# DataBinder.Eval(Container.DataItem, "ZIP") %></asp:TableCell></asp:TableRow>      
            <asp:TableRow Visible='<%# Not IsDBNull(DataBinder.Eval(Container.DataItem, "AREA_CODE")) and Not IsDBNull(DataBinder.Eval(Container.DataItem, "PHONE"))%>'>
                  <asp:TableCell>(<%# DataBinder.Eval(Container.DataItem, "AREA_CODE") %>) <%# DataBinder.Eval(Container.DataItem, "PHONE") %> </asp:TableCell></asp:TableRow>
            <asp:TableRow Visible='<%# Not IsDBNull(DataBinder.Eval(Container.DataItem, "AREA_CODE")) and Not IsDBNull(DataBinder.Eval(Container.DataItem, "FAX"))%>'>
                  <asp:TableCell><i>Fax: </i>(<%# DataBinder.Eval(Container.DataItem, "AREA_CODE") %>) <%# DataBinder.Eval(Container.DataItem, "FAX") %></asp:TableCell></asp:TableRow>
            <asp:TableRow Visible='<%# Not IsDBNull(DataBinder.Eval(Container.DataItem, "WEBSITE"))%>'>
                  <asp:TableCell> <a href='<%# DataBinder.Eval(Container.DataItem, "WEBSITE") %>' target=_blank>Website</a></asp:TableCell></asp:TableRow>
            <asp:TableRow>
                  <asp:TableCell><%# DataBinder.Eval(Container.DataItem, "MILES") %> miles</asp:TableCell></asp:TableRow>
      </asp:Table>
      </td>
      </tr>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
0
Comment
Question by:Leprechaun
2 Comments
 
LVL 10

Accepted Solution

by:
jnhorst earned 125 total points
ID: 12012636
Try this:

Define this class in a separate .cls file:  Change the if() statement in the IsDBNull() method to check for the string you want to skip.

Imports System;

Namespace System
      Public Class CustomFunctions
            Public Sub New()
                                End Sub

            Public Shared Function IsDBNull(Value As Object) As Boolean
                  return = (System.Convert.IsDBNull(Value) Or Value = "null");
            End Function
      End Class
End Namespace

Then instead of calling "Not IsDBNull(...) call "Not System.CustomFunctions.IsDBNull(...)

John
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now