473,320 Members | 1,988 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,320 software developers and data experts.

Repeater and Custom HTML Question

Hello,

How to control the structure of the HTML inside of the ItemTemplate of the
Repeater?

For example, if a certain data column value is empty (or contains some
specific string or number), I want to be able to "hide" a part of the HTML
of the ItemTemplate.

Say a customer has phone number and extension. The extension is optional.
When the extension is there, the phone should be displayed in this format:
123-555-6789 Ext: 123

If there is no extension, the phone should be simply: 123-555-6789.

I have the following ItemTemplate:

<ItemTemplate>
<tr>
<td>Phone:
<%#DataBinder.Eval(Container.DataItem,"phone")%>-x<%#DataBinder.Eval(Contain
er.DataItem,"extension")</td>
</tr>
</ItemTemplate>

However, this will produce an undesirable output if there is no extension:
123-555-6788 Ext:

What is the most appropriate way to avoid this? An example would be great!

I am sure may people have come across this, since it is very common to have
"very dynamic" HTML output that is dependent on the values of the data that
is bound to the Repeater control.

Thanks,
Arsen
Nov 18 '05 #1
1 1314
Jos
Arsen V. wrote:
Hello,

How to control the structure of the HTML inside of the ItemTemplate
of the Repeater?

For example, if a certain data column value is empty (or contains some
specific string or number), I want to be able to "hide" a part of the
HTML of the ItemTemplate.

Say a customer has phone number and extension. The extension is
optional. When the extension is there, the phone should be displayed
in this format: 123-555-6789 Ext: 123

If there is no extension, the phone should be simply: 123-555-6789.

I have the following ItemTemplate:

<ItemTemplate>
<tr>
<td>Phone:
<%#DataBinder.Eval(Container.DataItem,"phone")%>-x<%#DataBinder.Eval(Contain er.DataItem,"extension")</td>
</tr>
</ItemTemplate>

However, this will produce an undesirable output if there is no
extension: 123-555-6788 Ext:

What is the most appropriate way to avoid this? An example would be
great!

I am sure may people have come across this, since it is very common
to have "very dynamic" HTML output that is dependent on the values of
the data that is bound to the Repeater control.

Thanks,
Arsen


Write a function like this (this is for VB):

Function FormatPhoneExt(phone As Object, ext As Object) As String
If(ext.ToString()<>"")
Return phone.ToString() & " Ext: " & ext.ToString()
Else
Return phone
End If
End Function

Then, change the binding syntax to this:
<%# FormatPhoneExt(DataBinder.Eval(Container.DataItem, "phone"),
DataBinder.Eval(Container.DataItem,"extension") %>

--

Jos Branders
Nov 18 '05 #2

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

Similar topics

1
by: Arsen V. | last post by:
> Hello, > > How to control the structure of the HTML inside of the ItemTemplate of the > Repeater? > > For example, if a certain data column value is empty (or contains some > specific string...
3
by: Mark | last post by:
I am looking for an example of using checkboxes in a repeater control where the checkbox state is persisted from page to page. Thank you, Mark
2
by: Antoine | last post by:
I would like to construct my own list of items in a grid/ table/ item list layout but I have a problem. I want to add a sort of index row based on time, such as there might be blank values. Sure...
3
by: WebMatrix | last post by:
I am struggling with implementing somewhat complicated UI web-control. I explored Repeater, but I am not sure if it's the best way to go. I am leaning towards writing my own custom control and...
9
by: Jaybuffet | last post by:
my aspx has something like this <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <mycontrol:ctl id="ctlId" obj='<%# Container.DataItem %>' showItem="true"/> </ItemTemplate>...
3
by: Brian | last post by:
Using external XML, I'm trying to build a quiz, but I can't seem to specify the DataSource for the RadioButtonList within a Repeater ItemTemplate. I've tried a number of approaches, but I haven't...
5
by: Brad Baker | last post by:
I am trying to make a "tabbed" interface by iterating through a dataset with a conditional statement. For example: ...
1
by: jazzart | last post by:
Hi there, I'm fairly new to programming with Asp.Net 2.0 so I'm finding myself regularly fumbling around in the dark a bit, so to speak. I'm currently using Visual Web Developer and have been...
0
by: Murdz | last post by:
Hello. I have created a set of custom controls to spit out XML for a IVVR platform. This all works well; however there are instances I want to loop through an iteration spitting out chucks of XML...
12
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I'm doing a web app in VB/Dot Net 2.0. I'm probably a bit rusty and I have no experience using the repeater control. I have a user control I've created with multiple properties. I've created a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.