Can't get subroutine/helper function to work in Datalist control

C

Chumley the Walrus

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

....i get an "Expected end of statement " error on this line
 
M

Marina

Your argument to your function is of type string - but is that what the
column is in the database? Or is it an image column. As you would imagine,
you can't just turn an image into a string, since an image is binary data.

The 'end of statement' error is because a Sub cannot have a return type,
since Subs don't return anything, only Functions do.

I recommend you try using the code behind model to write your code, since
you will catch these errors before you try to run the page, and the messages
are IDE provides a better environment for figuring out why there is an
error.
 
J

John Saunders

Marina said:
Your argument to your function is of type string - but is that what the
column is in the database? Or is it an image column. As you would imagine,
you can't just turn an image into a string, since an image is binary data.

The 'end of statement' error is because a Sub cannot have a return type,
since Subs don't return anything, only Functions do.

I recommend you try using the code behind model to write your code, since
you will catch these errors before you try to run the page, and the messages
are IDE provides a better environment for figuring out why there is an
error.

In addition to Marina's comment, I suggest that you turn Options Strict On.
I believe it will catch more of this sort of problem.

Note that "Imagesubprod1" is of type String. What is the return type of
DataBinder.Eval?
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top