ASP.NET and Customer HTML

A

Arsen Vladimirskiy

Hello,

What is the proper way to implement the following:

1) We have a list of customers
2) Customers can have some optional fields. For example, second phone
number, comments, and others.
3) We need to display the customers in a list, but in a nicely formatted
way. In other words, if the customer has a second phone, we want to show it
nicely with the extension (if it has one), if there is no second phone, we
do not want to have to says: Phone 2 #: empty. Same goes for all the other
optional fields.

If we are using a Repeater, what is the right way to achive this? Should we
put the if-statements inside the <%# %> blocks in the .aspx file?

For example, should we do this:

<%#
if (DataBinder.Eval(Container.DataItem,"phone2") != "")
{
Response.Write("Phone 2#: " +
DataBinder.Eval(Container.DataItem,"phone2"));
if (DataBinder.Eval(Container.DataItem,"phone2ext") != "")

Response.Write("&nbsp;x-DataBinder.Eval(Container.DataItem,"phone2ext"));
}
%>

This seems too messy. Is this the right approach to handling custom html
inside repeaters?

Thanks,
Arsen
 
M

Marina

The way I've done this, is to have a Label in the item template, and set its
Visible property to True or False depending on whether the field was null.
The text property would be bound either way - but if the label wasn't
visible, then it wouldn't matter.

This allows you to see at design time exacltly the layout, but at render
time, those customer's with the optional field filled in will have it
displayed, and those without it will not.

You can extend this to a Panel, with several web control inside it. You
could bind the controls, but set the Visible property on the Panel. So
either the whole thing is visible, or nothing is.

If you are going to use Response.Write's to achieve this, you might as well
be using ASP...
 
A

Arsen Vladimirskiy

Hi Marina,

Did you change the Visible property to False or True in the code-behind?

Did you write a function to handle the OnItemCreated event of the Repeater?

Thanks,
Arsen
 
M

Marina

No, I did something like:

<asp:Label runat="server" Visible= '<%#
IIF(IsDBNull(Container.DataItem("MyCol")),False,True) %>' > <%#
Container.DataItem("MyCol") %> </asp:Label>

That's VB in the script, but easily changeable to C#.
 
A

Arsen Vladimirskiy

What is the equivalent of the IFF() command in C#?
Did you write the IFF() yourself?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top