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(" x-DataBinder.Eval(Container.DataItem,"phone2ext"));
}
%>
This seems too messy. Is this the right approach to handling custom html
inside repeaters?
Thanks,
Arsen
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...
"Arsen Vladimirskiy" <ar...@emergency24.com> wrote in message
news:uQOnEHky...@TK2MSFTNGP12.phx.gbl...
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
"Marina" <nospam> wrote in message
news:OX8WPRky...@tk2msftngp13.phx.gbl...
<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#.
"Arsen Vladimirskiy" <ar...@emergency24.com> wrote in message
news:%23iioyZk...@TK2MSFTNGP12.phx.gbl...
"Marina" <nospam> wrote in message
news:%23ZGzKQl...@tk2msftngp13.phx.gbl...