?
Solved

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

Posted on 2004-09-08
2
Medium Priority
?
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
jnhorst earned 500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

649 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