|
-
February 17th, 2006, 08:58 AM
#1
A little confused...
I have some classic asp that i am trying to convert to asp.net
I have started using item templates with the following code to call database feilds:<%# DataBinder.Eval(Container.DataItem, "Addressline1") %>
My problem is that i need to have an if then statment. If an image isnt present then load noimage.gif for instance:
<% if rs("CBanner") <> "" then %>
<td width="526" colspan="3" class="tablecells"><img src="images/DirectoryBanners/<%=cbanner%>" width="522"/></td>
<%else%>
<td width="526" colspan="3" class="tablecells"> </td>
<%end if%>
How on earth do i do this with::<%# DataBinder.Eval(Container.DataItem, "Addressline1") %>
or am imissing somthing
Cheers for any help
-
February 17th, 2006, 11:30 AM
#2
Re: A little confused...
The easiest method is to create a method that takes the content as a parameter and returns the correct string.
For example:
In the <script runat="server"> (or codebehind) section:
Code:
private string formatImage(string imagelocation)
{
string retval;
// Check if it exists - you may need to modify this if a different value is used
// ie, an empty string, etc.
if (imagestring != null)
{
retval = "<img src=\"images/DirectoryBanners/" + imagelocation + "\" width=\"522\"/>";
} else {
retval = " ";
}
return retval;
}
Then in your table do this:
Code:
<td width="526" colspan="3" class="tablecells">
<%# formatImage(DataBinder.Eval(Container.DataItem, "Addressline1").ToString()) %>
</td>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|