473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can't get a db value to evaluate to TRUE...why?

I've been struggling to get a repeater control set up to check a record
field, and, depending on what it is, render a different HTML template.

I've tried using a simple server-side span:

<span runat="server" Visible='<%# DataBinder.Eval(Container.DataItem,
"Application").ToString() = "Notice" %>'>
<custom html>
</span>

....and calling a function:

<%# TestSub(DataBinder.Eval(Container.DataItem, "Application"))%>

Function TestSub(ByVal YourItem as String)
If (YourItem="Notice") Then
Return "it works!"
Else
Return YourItem
End If
End Function

I've (FINALLY!) narrowed down the problem to the actual comparison. The same
thing happens with both methods...I can NOT get the data to evaluate to
TRUE. I've tried a number of things like:

<%# DataBinder.Eval(Container.DataItem, "Application") %>
= Notice

<%# DataBinder.Eval(Container.DataItem, "Application") = "Notice" %>
= False

<%# DataBinder.Eval(Container.DataItem, trim("Application")) =
trim("Application") %>
= False (this one REALLY has me stumped)

<%# Convert.ToBoolean(DataBinder.Eval(Container.DataIt em,
trim("Application")).ToString() = "Notice") %>
= False

So, it appears that I'm not comparing two identical things. And I'm not sure
what else to look at here. Is this an issue with SQL server, perhaps? Do I
need to caste these values as something completely different?
Nov 18 '05 #1
8 1021
> Maybe the text is "notice" instead of "Notice".

Not that I can tell. This is what is returned:
<%# DataBinder.Eval(Container.DataItem, "Application") %>
= Notice


with the uppercase Notice. Changing it to 'notice' in the comparison still
returns a false value.

-Darrel
Nov 18 '05 #2
I just set up a test, and it worked for me, can you post your entire
repeater tag/relavant functions just so we know exactly what you are trying
to do.

--Michael

btw here is what worked for me...working off of northwind db. I got many
bullets, but only text that showed up was "Fuller"

<asp:repeater id="Repeater1" runat="server">
<headertemplate><ul></headertemplate>
<itemtemplate><li><span runat="server" visible='<%#
DataBinder.Eval(Container.DataItem, "lastname") = "Fuller"%>'><%#
DataBinder.Eval(Container.DataItem, "lastname")%></span></li></itemtemplate>
<footertemplate></ul></footertemplate>
</asp:repeater>

Private conn As New
SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
conn.Open()

Dim sql As String
sql = "Select * from employees"

Dim cmd As New SqlCommand(sql, conn)
Dim dr As SqlDataReader =
cmd.ExecuteReader(CommandBehavior.CloseConnection)

Repeater1.DataSource = dr
Repeater1.DataBind()
End Sub

"darrel" <no*****@hotmail.com> wrote in message
news:ua**************@TK2MSFTNGP11.phx.gbl...
I've been struggling to get a repeater control set up to check a record
field, and, depending on what it is, render a different HTML template.

I've tried using a simple server-side span:

<span runat="server" Visible='<%# DataBinder.Eval(Container.DataItem,
"Application").ToString() = "Notice" %>'>
<custom html>
</span>

...and calling a function:

<%# TestSub(DataBinder.Eval(Container.DataItem, "Application"))%>

Function TestSub(ByVal YourItem as String)
If (YourItem="Notice") Then
Return "it works!"
Else
Return YourItem
End If
End Function

I've (FINALLY!) narrowed down the problem to the actual comparison. The same thing happens with both methods...I can NOT get the data to evaluate to
TRUE. I've tried a number of things like:

<%# DataBinder.Eval(Container.DataItem, "Application") %>
= Notice

<%# DataBinder.Eval(Container.DataItem, "Application") = "Notice" %>
= False

<%# DataBinder.Eval(Container.DataItem, trim("Application")) =
trim("Application") %>
= False (this one REALLY has me stumped)

<%# Convert.ToBoolean(DataBinder.Eval(Container.DataIt em,
trim("Application")).ToString() = "Notice") %>
= False

So, it appears that I'm not comparing two identical things. And I'm not sure what else to look at here. Is this an issue with SQL server, perhaps? Do I
need to caste these values as something completely different?

Nov 18 '05 #3
> I just set up a test, and it worked for me, can you post your entire
repeater tag/relavant functions just so we know exactly what you are trying to do.


Sure...though if it works fine for you, I'm wondering if it's an issue with
the data object in our database?

Here's the entire page (it's not that big). Right now, I'm just trying to
get the template to return 'It Works!" if the data field = "Notice" (which,
AFAICT, it DOES, but still resolves to FALSE). Right now, when I run the
page, it doesn't equate the data field = Notice, so just returns the data
field, which shows up as (inexeplicably) 'Notice' (instead of 'It Works!')

================================================== =================

<%@ Control Language="vb" %>

<script runat="server">
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim strConnect As String
strConnect = ConfigurationSettings.AppSettings("DBConn")
Dim strChk As String
strChk = "Select top 10 Postid, postdate, Application, title FROM
WePostings order by Postdate DESC "

Try
'Dim objConnect As New OleDb.OleDbConnection(strConnect)
Dim objConnect As New System.Data.OleDb.OleDbConnection(strConnect)
objConnect.Open()
'Dim objCommand As New OleDb.OleDbCommand(strChk, objConnect)
Dim objCommand As New System.Data.OleDb.OleDbCommand(strChk, objConnect)
Repeater1.DataSource = objCommand.ExecuteReader()
Repeater1.DataBind()
Catch objError As Exception
' outMessage.InnerHtml = "Error accessing Database.<br />"
_
' & objError.Message & "<br />" & objError.Source
Exit Sub
End Try

End Sub

Function TestSub(ByVal YourItem as String)
If (YourItem="Notice") Then
Return "it works!"
Else
Return YourItem
End If
End Function

</script>
<form runat="server">
<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>

<%# TestSub(DataBinder.Eval(Container.DataItem, "Application"))%>

</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
</form>
Nov 18 '05 #4
still works for me, have you tried using the function
String.Compare(YourItem, "Notice") = true for your comparison?

You may want to specify a return type for your function, although I already
tested it and it didn't make a difference to me, still it's best to avoid
uneeded conversions in the background.

Function TestSub(ByVal YourItem as String) as String

Can you debug and see what is in each variable at runtime?

Also why are you using oledbconnection, oledbreaders, etc. I guess they'd
work, but sqlconnection/sqlreader/etc. are optimized for just sql server so
you should use them.

--Michael
"darrel" <no*****@hotmail.com> wrote in message
news:OR**************@TK2MSFTNGP12.phx.gbl...
I just set up a test, and it worked for me, can you post your entire
repeater tag/relavant functions just so we know exactly what you are trying
to do.


Sure...though if it works fine for you, I'm wondering if it's an issue

with the data object in our database?

Here's the entire page (it's not that big). Right now, I'm just trying to
get the template to return 'It Works!" if the data field = "Notice" (which, AFAICT, it DOES, but still resolves to FALSE). Right now, when I run the
page, it doesn't equate the data field = Notice, so just returns the data
field, which shows up as (inexeplicably) 'Notice' (instead of 'It Works!')

================================================== =================

<%@ Control Language="vb" %>

<script runat="server">
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim strConnect As String
strConnect = ConfigurationSettings.AppSettings("DBConn")
Dim strChk As String
strChk = "Select top 10 Postid, postdate, Application, title FROM
WePostings order by Postdate DESC "

Try
'Dim objConnect As New OleDb.OleDbConnection(strConnect)
Dim objConnect As New System.Data.OleDb.OleDbConnection(strConnect)
objConnect.Open()
'Dim objCommand As New OleDb.OleDbCommand(strChk, objConnect)
Dim objCommand As New System.Data.OleDb.OleDbCommand(strChk, objConnect) Repeater1.DataSource = objCommand.ExecuteReader()
Repeater1.DataBind()
Catch objError As Exception
' outMessage.InnerHtml = "Error accessing Database.<br />" _
' & objError.Message & "<br />" & objError.Source
Exit Sub
End Try

End Sub

Function TestSub(ByVal YourItem as String)
If (YourItem="Notice") Then
Return "it works!"
Else
Return YourItem
End If
End Function

</script>
<form runat="server">
<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>

<%# TestSub(DataBinder.Eval(Container.DataItem, "Application"))%>

</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
</form>

Nov 18 '05 #5
> still works for me,

So, would that indicate that something is goofy with the data coming from
the database? I'm not sure how, exactly, you are testing it. Are you getting
a TRUE return, or just that it does return 'NOTICE'?
have you tried using the function
String.Compare(YourItem, "Notice") = true for your comparison?
Let me try...

Function TestSub(ByVal YourItem as String)
If String.Compare(YourItem, "Notice") = true Then
Return "it's true!"
Else
Return "it's false!"
End If
End Function

returns... 'it's false'. Replacing that with Return YourItem returns
'Notice'...which just doesn't make any sense. *sigh*.

Note that even before I couldn't get a comparison of itself to itself to
return 'true'.
Function TestSub(ByVal YourItem as String) as String
Yep...same results for me.
Can you debug and see what is in each variable at runtime?
Umm...no. I'm actually avoiding VS.NET right now and doing most of this by
hand in DW. Is there a way to debug sans VS.NET?
Also why are you using oledbconnection, oledbreaders, etc. I guess they'd
work, but sqlconnection/sqlreader/etc. are optimized for just sql server so you should use them.


Oh. Well, I'm just learning, so I'll have to go look at that! Thanks for the
tip.

Thanks for working on this, though. I'm still completely befuddled as to why
it won't work here on my end.

-Darrel
Nov 18 '05 #6
AAAAARRRRRGGGGGGGGGHHHHHHHHHHHHHHHH!

Michael:

As soon as I posted that last reply, I realized what was going on. The
repeat is checking only the first record. In otherwords, the first record
happens to *not* be a 'Notice* so it is returning a 'false'. Now, to figure
out how to get it to check each individual record instead of just the first
one...

-Darrel
Nov 18 '05 #7
Gah. I have NO IDEA how I finally got to this, but this works!:

If (trim(YourItem)="Notice") Then
Return "it works!"

so...I think this means that the database is storing more than just 'Notice'
but is including blank spaces?

-Darrel
Nov 18 '05 #8
mmm, spaces in the fields, now that problem has thrown me off many of times,
especially when you import from text files, if you don't watch it sometimes
it'll throw spaces in the fields.

"darrel" <no*****@hotmail.com> wrote in message
news:Op**************@TK2MSFTNGP09.phx.gbl...
Gah. I have NO IDEA how I finally got to this, but this works!:

If (trim(YourItem)="Notice") Then
Return "it works!"

so...I think this means that the database is storing more than just 'Notice' but is including blank spaces?

-Darrel

Nov 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chumley the Walrus | last post by:
I need to evaluate a field's maximum value and then do an if conditional: if rs("havesubP") = true and rs("displaygroup") < MAX then .... whereas MAX represents the biggest value in the...
9
by: Carlis | last post by:
I want to make a program that, when you have the mouse on a word, that word is bold... and when you don't have the mouse on that word, the word is not bold. Excuse me for my poor English :-( But...
5
by: Steve | last post by:
Hello, I've been a PHP programmer for a number of years and have just started to learn JS. My Employer (a water analysis lab) wants what should be a very simple .js written that basically takes...
19
by: Mark A. Odell | last post by:
Is NULL guaranteed to evaluate 'not true', e.g. is it completely safe and portable to write: char *pFoo = malloc(1024); if (pFoo) { /* use pFoo */ free(pFoo); }
3
by: Jan Nielsen | last post by:
Hi I am working with rowfilters in dataviews. I would like to filter for empty fields (= null value in the database) I found this sentence on msdn: **************** To return only those columns...
0
by: KenRoy | last post by:
I want to be able to evaluate a string value as either True or False. So if the string was "0 Or (1 or 0)" the value True would be returned. My ultimate goal would be to have a statement similar...
21
by: Steven T. Hatton | last post by:
I'm trying to improve my formal understanding of C++. One significant part of that effort involves clarifying my understanding of the vocabulary used to describe the language. This is from the...
23
by: gamename | last post by:
Hi Right now I do multiple asserts to verify multiple values: assert(foo==X); assert(foo==Y); assert(foo==Z); Is there any way to macro-ize this and do it in one call? MYASRT(foo,...
3
gingawarrior
by: gingawarrior | last post by:
Hi All, I've written some code to act as a validator for a set of form fields - it accepts a string of '~' delimited item names and then loops through to evaluate if they are either empty or =='999'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.