Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Can't get subroutine/helper function to work in Datalist control

Reply
Thread Tools

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

 
 
Chumley the Walrus
Guest
Posts: n/a
 
      06-14-2004
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
 
Reply With Quote
 
 
 
 
Marina
Guest
Posts: n/a
 
      06-14-2004
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.

"Chumley the Walrus" <> wrote in message
news: om...
> 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



 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      06-15-2004
"Marina" <> wrote in message
news:...
> 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?
--
John Saunders
johnwsaundersiii at hotmail

> "Chumley the Walrus" <> wrote in message
> news: om...
> > 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

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataList inside user control - ItemCommands don't work if I dont populate List on every page load yousuf ASP .Net 0 01-29-2006 11:49 PM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM
Can't get subroutine/helper function to work in Datalist control Chumley the Walrus ASP .Net Web Controls 1 06-14-2004 08:32 PM
DataList in DataList acko bogicevic ASP .Net 2 11-11-2003 08:31 AM
Datalist in Datalist How? Gönen EREN ASP .Net 0 08-22-2003 02:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57