473,473 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Repeater: condition of a field being blank or not? to Tag or not to Tag

I have the following inside a repeater:

<ItemTemplate>
<b><%#Container.DataItem("TitleText")%></b><br />
<%#Container.DataItem("ParagraphText")%>

<br /><br />
</ItemTemplate>
if for some reason, the TitleText is blank or null I'd like to not have
the <br/tag. In other words, I only want the <br/tag if TitleText
has something in it.
Can I do this, and if so, how best to accomplish?

Dec 7 '06 #1
2 1532
There are a number of ways, the cleanest and one that'll scale the best is
to hook into the ItemDataBound event of your repeater and control the output
programatically.

For example, you could do:

<asp:literal id="Extra" runat="server"><br /><br /></asp:Literal>

and in the ItemDataBound do:

if (records are null)
{
((Literal)e.Item.FindControl("Extra")).Visible = false;
}

You can read up more at:
http://openmymind.net/index.aspx?documentId=8#4.2

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"HockeyFan" <le**********@gmail.comwrote in message
news:11*********************@j72g2000cwa.googlegro ups.com...
>I have the following inside a repeater:

<ItemTemplate>
<b><%#Container.DataItem("TitleText")%></b><br />
<%#Container.DataItem("ParagraphText")%>

<br /><br />
</ItemTemplate>
if for some reason, the TitleText is blank or null I'd like to not have
the <br/tag. In other words, I only want the <br/tag if TitleText
has something in it.
Can I do this, and if so, how best to accomplish?
Dec 7 '06 #2
I ended up solving the problem as follows:

<ItemTemplate>
<b><%#Container.DataItem("TitleText")%></b><%#IsBlankOrNull(Container.DataItem("TitleText") ,
"", "<br />")%>
<%#Container.DataItem("ParagraphText")%>

<br /><br />
</ItemTemplate>

and then the following in my base class:

Public Function IsBlankOrNull(ByVal blnValue As Object, ByVal
objValueIfTrue As String, ByVal objValueIfFalse As String) As String
If blnValue Is DBNull.Value Then
Return objValueIfFalse
ElseIf CType(blnValue, String) = Nothing Then
Return objValueIfFalse
Else
If CType(blnValue, String) = "" Then
Return objValueIfFalse
Else
Return objValueIfTrue
End If
End If
End Function
Karl Seguin wrote:
There are a number of ways, the cleanest and one that'll scale the best is
to hook into the ItemDataBound event of your repeater and control the output
programatically.

For example, you could do:

<asp:literal id="Extra" runat="server"><br /><br /></asp:Literal>

and in the ItemDataBound do:

if (records are null)
{
((Literal)e.Item.FindControl("Extra")).Visible = false;
}

You can read up more at:
http://openmymind.net/index.aspx?documentId=8#4.2

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"HockeyFan" <le**********@gmail.comwrote in message
news:11*********************@j72g2000cwa.googlegro ups.com...
I have the following inside a repeater:

<ItemTemplate>
<b><%#Container.DataItem("TitleText")%></b><br />
<%#Container.DataItem("ParagraphText")%>

<br /><br />
</ItemTemplate>
if for some reason, the TitleText is blank or null I'd like to not have
the <br/tag. In other words, I only want the <br/tag if TitleText
has something in it.
Can I do this, and if so, how best to accomplish?
Dec 7 '06 #3

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

Similar topics

4
by: Bernie V | last post by:
Hi group, Is it possible to use a condition in a repeater control ? I 'd like to use a condition to create this <a href='<%#DataBinder.Eval(Container.DataItem,"nieuwsid")%>.aspx'> part of the...
1
by: Henry Nelson | last post by:
Hi all I'm very new to dotNet and just trying to get my head around the right way to do the thing that I would normally do in asp. In asp I would loop through a recordset and output all the...
2
by: rwoo_98 | last post by:
I am working on a web form that allows the user to add a new row. Basically I query the data from a database and store it in a dataset. I add a new row to the table in the dataset: DataRow dr =...
3
by: sorCrer | last post by:
Hi All, Posted after extensive searching! I have a nested repeater control as follows: (Simplified ;-)) <table> <asp:repeater id=parent onItemDataBound=createChild> <tr><td>Level...
3
by: Andrew | last post by:
Hi, I am working on a questionnaire. I have displayed a questionnaire using a repeater control. The itemtemplate is as below (quite cut down): <ItemTemplate> <tr><td> <%#...
5
by: DaveLock | last post by:
Hi, I have 3 tables of data created from different sources, each with the same 2 fields & I wanted to fill the 2nd field of another table with the data on condition. The condition is because...
2
by: Mick Walker | last post by:
Hi Everyone, I am binding my repeater from a Paged Data source I populate in my code behind. I am wondering How do I set some default text if a value is null (or a empty string) I am...
4
by: exrcizn | last post by:
I am creating a query in Access 2003 that basically displays data in certain fields in a table (plain and simple basic stuff). I have a field in the table that may or may not contain data. If the...
4
by: Michael | last post by:
I have a repeater web control. Currently I want to change some row's color based on defined condition. Is there any code sample demonstrating how to accomplish it? Thanks.
0
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...
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...
0
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.