By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,759 Members | 1,712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,759 IT Pros & Developers. It's quick & easy.

Repeater and Custom HTML Question

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.