Groups | Blog | Home
all groups > asp.net webcontrols > june 2004 >

asp.net webcontrols : Can't get subroutine/helper function to work in Datalist control


springb2k NO[at]SPAM yahoo.com
6/14/2004 10:22:08 AM
I'm using a subroutine/helper function display an image (the image
would be displayed inside a datalist control's <itemtemplate> )

<script language="VB" runat="server">
Public Sub checkforimg(ByVal Imagesubprod1 As String)
If Imagesubprod1 <> "" then
response.write(Imagesubprod1)
Else
response.write("nbsp;")
End If
End Sub
</script>

..... but I get an "Overload resolution failed because no accessible
'ToString' can be called with these arguments:" error when it comes
time to check for the image as follows.

<%# checkforimg(DataBinder.Eval(Container.DataItem,
"Imagesubprod1"))%>

When I form the header for the sub as follows:
Public Sub checkforimg(ByVal Imagesubprod1 As String) As string

Ken Cox [Microsoft MVP]
6/14/2004 4:32:57 PM
You want to use a Function rather than a Sub and make sure it returns a
string.

Actually, you might be able to shorten the process by using IIF right in
your .aspx file:

<asp:Image id="Image1" runat="server" ImageUrl='<%#
iif(DataBinder.Eval(Container.DataItem,
"StringValue")="","&nbsp;",DataBinder.Eval(Container.DataItem,"StringValue"))
%>'>

Ken


[quoted text, click to view]
AddThis Social Bookmark Button