473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Conditionally write a Template Item is data in field exists?

I'm using ASP.NET (VB) and I'm pretty new to .NET and using Templates.

I have a SqlDataReader which is bound to a Repeater. The Repeater contains
a table and for each record, it'll write a table. Easy stuff so far. My
table contains typical Address and Phone numbers data. What I'd like to do
is check to see if "Address2" (field) is empty and/or null. If so then skip
the line all together, but if it does contain something, write:

<%# Container.DataItem("Address2") %><br />

Make sense? I'm trying to avoid having an empty line between Address2 and
City, State Zip. I've experimented with a "helper function" by sending
Address2 to a Function and have it send back nothing or literally the HTML
to complete this line. But again, if it's null, it errors. Hmmm. What to
do??

I would appreciate any pointers or advice.
<asp:Repeater ID="rptProviders" Runat="Server">
<ItemTemplate>

<table width="95%" border="0" align="center" cellpadding="5"
cellspacing="0" class="grid">
<tr>
<td class="colheader">(<% =intGlobalCounter %>) <%#
Container.DataItem("OrgName") %></td>
</tr>

<tr>
<td>
<p align="center"><img src="../assets/providers/<%#
Container.DataItem("Photo") %>" class="imgborder" border="0" /></p>
<p><%# Container.DataItem("ProfileDescription") %></p>
<p>Serving: Area 1, Area 2, Area 3</p>
<p><%# Container.DataItem("Address") %><br />
<%# Container.DataItem("Address2") %><br />
<%# Container.DataItem("City") %>, <%# Container.DataItem("State") %> <%#
Container.DataItem("Zip") %><br />
<%# Container.DataItem("Phone") %><br />
<%# Container.DataItem("Fax") %><br />
<a href="mailto:<%# Container.DataItem("ContactEmail") %>"><%#
Container.DataItem("ContactEmail") %></a><br />
<a href="<%# Container.DataItem("WebSite") %>" target="_blank"><%#
Container.DataItem("WebSite") %></a></p></td>
</tr>
</table>
<% intGlobalCounter = intGlobalCounter + 1 %>
</ItemTemplate>
</asp:Repeater>
Nov 18 '05 #1
2 1325
You can use something like this:

Public Shared Function no_null_string(ByVal value As Object) As String
If value Is System.DBNull.Value Then
Return String.Empty
Else
Return value.ToString
End If
End Function

"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:OL**************@TK2MSFTNGP10.phx.gbl...
I'm using ASP.NET (VB) and I'm pretty new to .NET and using Templates.

I have a SqlDataReader which is bound to a Repeater. The Repeater contains a table and for each record, it'll write a table. Easy stuff so far. My
table contains typical Address and Phone numbers data. What I'd like to do is check to see if "Address2" (field) is empty and/or null. If so then skip the line all together, but if it does contain something, write:

<%# Container.DataItem("Address2") %><br />

Make sense? I'm trying to avoid having an empty line between Address2 and
City, State Zip. I've experimented with a "helper function" by sending
Address2 to a Function and have it send back nothing or literally the HTML
to complete this line. But again, if it's null, it errors. Hmmm. What to do??

I would appreciate any pointers or advice.
<asp:Repeater ID="rptProviders" Runat="Server">
<ItemTemplate>

<table width="95%" border="0" align="center" cellpadding="5"
cellspacing="0" class="grid">
<tr>
<td class="colheader">(<% =intGlobalCounter %>) <%#
Container.DataItem("OrgName") %></td>
</tr>

<tr>
<td>
<p align="center"><img src="../assets/providers/<%#
Container.DataItem("Photo") %>" class="imgborder" border="0" /></p>
<p><%# Container.DataItem("ProfileDescription") %></p>
<p>Serving: Area 1, Area 2, Area 3</p>
<p><%# Container.DataItem("Address") %><br />
<%# Container.DataItem("Address2") %><br />
<%# Container.DataItem("City") %>, <%# Container.DataItem("State") %> <%# Container.DataItem("Zip") %><br />
<%# Container.DataItem("Phone") %><br />
<%# Container.DataItem("Fax") %><br />
<a href="mailto:<%# Container.DataItem("ContactEmail") %>"><%#
Container.DataItem("ContactEmail") %></a><br />
<a href="<%# Container.DataItem("WebSite") %>" target="_blank"><%#
Container.DataItem("WebSite") %></a></p></td>
</tr>
</table>
<% intGlobalCounter = intGlobalCounter + 1 %>
</ItemTemplate>
</asp:Repeater>

Nov 18 '05 #2
I'm sure a helper function could pull this off. What sort of error
were you getting and what did the code look like? You might just need
a little bit of logic to avoid a null reference.

--
Scott
http://www.OdeToCode.com

On Fri, 30 Apr 2004 11:47:42 -0400, "D. Shane Fowlkes"
<sh**********@h-o-t-m-a-i-l.com> wrote:
I'm using ASP.NET (VB) and I'm pretty new to .NET and using Templates.

I have a SqlDataReader which is bound to a Repeater. The Repeater contains
a table and for each record, it'll write a table. Easy stuff so far. My
table contains typical Address and Phone numbers data. What I'd like to do
is check to see if "Address2" (field) is empty and/or null. If so then skip
the line all together, but if it does contain something, write:

<%# Container.DataItem("Address2") %><br />

Make sense? I'm trying to avoid having an empty line between Address2 and
City, State Zip. I've experimented with a "helper function" by sending
Address2 to a Function and have it send back nothing or literally the HTML
to complete this line. But again, if it's null, it errors. Hmmm. What to
do??

I would appreciate any pointers or advice.
<asp:Repeater ID="rptProviders" Runat="Server">
<ItemTemplate>

<table width="95%" border="0" align="center" cellpadding="5"
cellspacing="0" class="grid">
<tr>
<td class="colheader">(<% =intGlobalCounter %>) <%#
Container.DataItem("OrgName") %></td>
</tr>

<tr>
<td>
<p align="center"><img src="../assets/providers/<%#
Container.DataItem("Photo") %>" class="imgborder" border="0" /></p>
<p><%# Container.DataItem("ProfileDescription") %></p>
<p>Serving: Area 1, Area 2, Area 3</p>
<p><%# Container.DataItem("Address") %><br />
<%# Container.DataItem("Address2") %><br />
<%# Container.DataItem("City") %>, <%# Container.DataItem("State") %> <%#
Container.DataItem("Zip") %><br />
<%# Container.DataItem("Phone") %><br />
<%# Container.DataItem("Fax") %><br />
<a href="mailto:<%# Container.DataItem("ContactEmail") %>"><%#
Container.DataItem("ContactEmail") %></a><br />
<a href="<%# Container.DataItem("WebSite") %>" target="_blank"><%#
Container.DataItem("WebSite") %></a></p></td>
</tr>
</table>
<% intGlobalCounter = intGlobalCounter + 1 %>
</ItemTemplate>
</asp:Repeater>


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jjouett | last post by:
I have XML that looks like the following: <top> <heart> <user>bob</user> <user>tim-o</user> <user>joe-i</user> <user>harvey</user> </heart> </top>
10
by: SueB | last post by:
I currently have a 'mail-merge' process in my Access db project. It generates custom filled out Award Certificates based on an SQL SELECT statement in a VBA routine invoked by clicking on a...
0
by: D. Shane Fowlkes | last post by:
OK - I'm looking for the best approach on how to do this. I have a form page where the user can edit their "Profile" (data) which is in SQL Server. It's your basic company information - address,...
0
by: D. Shane Fowlkes | last post by:
OK - I'm looking for the best approach on how to do this. I have a form page where the user can edit their "Profile" (data) which is in SQL Server. It's your basic company information - address,...
0
by: wwcoop | last post by:
I am connected to an Access Database. I am reading a Yes/No field from the DB which translates back as True/False in the text field of my datagrid. I want to use a checkbox to show the value...
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
6
by: Bartholomew Simpson | last post by:
I'm trying to avoid (or at least, minimize) duplicity of effort. I have the following function: void Permissions::Exists(const unsigned int id, std::vector<Permission>::const_iterator& iter) {...
3
by: yasmin | last post by:
I am trying to conditionally compile macros in my c++ program. I want to simply be able to use the macro name without enclosing it in #ifdef-#endif each time. How can I enclose the macro definition...
1
by: Joe Strout | last post by:
Wow, this was harder than I thought (at least for a rusty Pythoneer like myself). Here's my stab at an implementation. Remember, the goal is to add a "match" method to Template which works like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.