Solved

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

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can my static class become undefined?? 8 49
mail.To.Add 5 26
Modal Popup Extender control 1 20
Convert Select to DropDownListFor MVC 5 2 14
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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