Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Repeater and Custom HTML Question

Reply
Thread Tools

Repeater and Custom HTML Question

 
 
Arsen V.
Guest
Posts: n/a
 
      12-25-2003
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


 
Reply With Quote
 
 
 
 
Jos
Guest
Posts: n/a
 
      12-25-2003
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


 
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
repeater inside a repeater problem. uncensored ASP .Net 0 10-25-2006 06:10 PM
Custom control within repeater with custom object binding - .net 1 =?Utf-8?B?SmF5YnVmZmV0?= ASP .Net 9 02-21-2006 03:38 AM
Repeater inside a repeater....how? voidfill3d@yahoo.com ASP .Net 1 08-10-2005 01:58 PM
Repeater Using Javascript Referencing a Column in the Repeater rwoo_98@yahoo.com ASP .Net 0 02-26-2005 05:02 PM
Repeater control with nested repeater chris.reed@digus.com ASP .Net 0 02-11-2005 05:10 PM



Advertisments