473,592 Members | 2,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.DataI tem("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="rptProvider s" Runat="Server">
<ItemTemplate >

<table width="95%" border="0" align="center" cellpadding="5"
cellspacing="0" class="grid">
<tr>
<td class="colheade r">(<% =intGlobalCount er %>) <%#
Container.DataI tem("OrgName") %></td>
</tr>

<tr>
<td>
<p align="center"> <img src="../assets/providers/<%#
Container.DataI tem("Photo") %>" class="imgborde r" border="0" /></p>
<p><%# Container.DataI tem("ProfileDes cription") %></p>
<p>Serving: Area 1, Area 2, Area 3</p>
<p><%# Container.DataI tem("Address") %><br />
<%# Container.DataI tem("Address2") %><br />
<%# Container.DataI tem("City") %>, <%# Container.DataI tem("State") %> <%#
Container.DataI tem("Zip") %><br />
<%# Container.DataI tem("Phone") %><br />
<%# Container.DataI tem("Fax") %><br />
<a href="mailto:<% # Container.DataI tem("ContactEma il") %>"><%#
Container.DataI tem("ContactEma il") %></a><br />
<a href="<%# Container.DataI tem("WebSite") %>" target="_blank" ><%#
Container.DataI tem("WebSite") %></a></p></td>
</tr>
</table>
<% intGlobalCounte r = intGlobalCounte r + 1 %>
</ItemTemplate>
</asp:Repeater>
Nov 18 '05 #1
2 1340
You can use something like this:

Public Shared Function no_null_string( ByVal value As Object) As String
If value Is System.DBNull.V alue 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******** ******@TK2MSFTN GP10.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.DataI tem("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="rptProvider s" Runat="Server">
<ItemTemplate >

<table width="95%" border="0" align="center" cellpadding="5"
cellspacing="0" class="grid">
<tr>
<td class="colheade r">(<% =intGlobalCount er %>) <%#
Container.DataI tem("OrgName") %></td>
</tr>

<tr>
<td>
<p align="center"> <img src="../assets/providers/<%#
Container.DataI tem("Photo") %>" class="imgborde r" border="0" /></p>
<p><%# Container.DataI tem("ProfileDes cription") %></p>
<p>Serving: Area 1, Area 2, Area 3</p>
<p><%# Container.DataI tem("Address") %><br />
<%# Container.DataI tem("Address2") %><br />
<%# Container.DataI tem("City") %>, <%# Container.DataI tem("State") %> <%# Container.DataI tem("Zip") %><br />
<%# Container.DataI tem("Phone") %><br />
<%# Container.DataI tem("Fax") %><br />
<a href="mailto:<% # Container.DataI tem("ContactEma il") %>"><%#
Container.DataI tem("ContactEma il") %></a><br />
<a href="<%# Container.DataI tem("WebSite") %>" target="_blank" ><%#
Container.DataI tem("WebSite") %></a></p></td>
</tr>
</table>
<% intGlobalCounte r = intGlobalCounte r + 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.DataI tem("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="rptProvider s" Runat="Server">
<ItemTemplate >

<table width="95%" border="0" align="center" cellpadding="5"
cellspacing="0 " class="grid">
<tr>
<td class="colheade r">(<% =intGlobalCount er %>) <%#
Container.Data Item("OrgName") %></td>
</tr>

<tr>
<td>
<p align="center"> <img src="../assets/providers/<%#
Container.Data Item("Photo") %>" class="imgborde r" border="0" /></p>
<p><%# Container.DataI tem("ProfileDes cription") %></p>
<p>Serving: Area 1, Area 2, Area 3</p>
<p><%# Container.DataI tem("Address") %><br />
<%# Container.DataI tem("Address2") %><br />
<%# Container.DataI tem("City") %>, <%# Container.DataI tem("State") %> <%#
Container.Data Item("Zip") %><br />
<%# Container.DataI tem("Phone") %><br />
<%# Container.DataI tem("Fax") %><br />
<a href="mailto:<% # Container.DataI tem("ContactEma il") %>"><%#
Container.Data Item("ContactEm ail") %></a><br />
<a href="<%# Container.DataI tem("WebSite") %>" target="_blank" ><%#
Container.Data Item("WebSite") %></a></p></td>
</tr>
</table>
<% intGlobalCounte r = intGlobalCounte r + 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
1518
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
2471
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 command button. The "problem": I want to conditionally insert some text into the award certificate based on a field selected by the SELECT statement. Is this possible? Details: One of the fields selected is a concatenation of a value from a table
0
1534
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, phone numbers, etc. I also have on the form a CheckListBox which is bound to another table in SQL Server - let's assume it the USA States so there's 50 checkboxes dynamically written to the page. When the user "adds" their data, they check all...
0
1598
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, phone numbers, etc. I also have on the form a CheckListBox which is bound to another table in SQL Server - let's assume it the USA States so there's 50 checkboxes dynamically written to the page. When the user "adds" their data, they check all...
0
1075
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 instead of text. I have set up the template column using the datagrid properties wizard. Within "Edit Template" mode I have put two checkboxes into the "Item Template"
3
13734
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. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should always confirm a delete action. There is also a consensus that the best way to do this is a template...
6
1718
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) { if (m_permissions.empty()) iter = m_permissions.end() ; std::vector<Permission>::const_iterator cit=m_permissions.begin();
3
1760
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 itself in a #ifdef-#endif? Here's my example: #define FAULT { \ if (test.exists()) { \ return error( "Aborting" ); \
1
3425
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 Template.substitute, but in reverse: given a string, if that string matches the template, then it should return a dictionary mapping each template field to the corresponding value in the given string. Oh, and as one extra feature, I want to...
0
7871
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8236
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8227
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6642
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3851
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3893
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1202
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.