Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Repeater: condition of a field being blank or not? to Tag or not to Tag

Reply
Thread Tools

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

 
 
HockeyFan
Guest
Posts: n/a
 
      12-07-2006
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?

 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      12-07-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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?
>


 
Reply With Quote
 
 
 
 
HockeyFan
Guest
Posts: n/a
 
      12-07-2006
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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?
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with while condition OR condition Bill W. Ruby 13 05-09-2011 09:42 PM
javascript validation for a not required field, field is onlyrequired if another field has a value jr Javascript 3 07-08-2010 10:33 AM
1.Enter space bar for field names and save the field.The field shoud not get saved and an alert should be there as"Space bars are not allowed" Sound Javascript 2 09-28-2006 02:43 PM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
Condition outside loop or separate loop for different condition? - Java 12 06-15-2005 08:50 AM



Advertisments