Solved

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

Posted on 2004-09-08
2
264 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 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

691 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