Syntax Problem

W

Wayne Wengert

I am working through some ASP.NET tutorials and trying to adapt some of them
to my data. I built an aspx page that pulls data from an SQL server with a
query and use a repeater control to display it. As long as I use the format
of:

<ItemTemplate>
<tr bgcolor="#f0f0f0">
<td><%#Container.DataItem("CircuitName")%> </td>
<td><%#Container.DataItem("CircuitCity")%> </td>
<td><%#Container.DataItem("CircuitState")%> </td>

things work great but I need to apply some processing to some of the data
and when I try code like:

<%
If (Len(#Container.DataItem("WebPageURL")) <2) Then
Response.Write( "<td>None Given</td>")
Else
........

I get errors such as the following:

Compiler Error Message: BC30201: Expression expected.

Source Error:



Line 54: <%
Line 55: Dim tmpSTR
Line 56: If (Len(#Container.DataItem("WebPageURL")) <2) Then
Line 57: Response.Write( "<td>None Given</td>")
Line 58: Else

It appears that it doesn't like the way I am trying to check the length of
the field.

Any pointers to how this should be done?

TIA

Wayne
 
J

John Timney \(Microsoft MVP\)

You need to wrap your dataitem value with a function call

<%#BOB(Container.DataItem("CircuitName").ToString())%>

Sorry (not very up on VB.NET.so syntax might be a bit wierd but you'll get
the idea

Function bob(string fred)
If (Len fred)) <2) Then
Return( "<td>None Given</td>")
End If
End Function

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
 
C

Cowboy \(Gregory A. Beamer\)

The problem here is the mixture of declarative and programatic logic. This
does not work with data-binding. You can bind to a function call, as John
(another response to your post) has mentioned, which is a good compromise.

I think the following is a bit more correct VB.NET syntax:

Protected Function BOB(fred As String)

'To get rid of magic strings
Const returnString As String = "<td>None Given</td>"

'Opted for .NET version, rather than VB LEN() function
If (fred.Length < 2) Then
Return returnString
Else
Return fred
End If

End Function

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
W

Wayne Wengert

Thanks for the responses guys. I need to do some reading. Some things in
..NET are so intuitive and then there are some that are hard to grasp!

Wayne
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top