Does anyone know how to work with a datalist and an If Statement?

  • Thread starter Thread starter Mark Sandfox
  • Start date Start date
M

Mark Sandfox

This is my third posting on this issue. If I am asking for help on
something that cannot be done could someone please let me know this. I
cannot find any documentation anywhere on this.

What I am trying to do is:

If "EventLink is not blank" then
Insert a hypertextlink to external page with a header of "More
Information" (Note: User/Client enters in the URL)
else
Do Nothing
end if

My problem lay in that normal code does not seem to want to function with
the DataList DataItem.


Error Meesage:
BC30451: Name 'Container' is not declared.

Excerpt of code

<form Runat="Server">
<asp:DataList ID="dlstCalendar" Runat="server">
<ItemTemplate>
<div align="left">
<table border="0" cellpadding="0" cellspacing="0"
style="border-collapse: collapse" bordercolor="#111111" width="600">
<tr>
<td align="center" valign="top"><font face="Arial">
* <%if Container.DataItem("EventLink") <> "" then%>
<a target="_blank" href="http://<%#
Container.DataItem("EventLink")%>">More Information</a>
<%End If %>
</font></td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:DataList>
</form>


Thank you in advance for all your help.
 
"Container" is not available from the page as you are trying, it's
databinding syntax, available when the item is bound.
I suggest you say something like:
<a target="_blank" href='<%# MyFunction(Container.DataItem("myID")) %>'>More
Information</a>

where myfunction is a function in the codebehind thats returns the link,
myID is your variable and the whole thing is in the itemtemplate of your
datalist. Remeber to Databind() or nothing will happen.

tired, must sleep...
-fs
 
Back
Top