473,802 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Data Item,
"Application"). ToString() = "Notice" %>'>
<custom html>
</span>

....and calling a function:

<%# TestSub(DataBin der.Eval(Contai ner.DataItem, "Application")) %>

Function TestSub(ByVal YourItem as String)
If (YourItem="Noti ce") 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.Data Item, "Applicatio n") %>
= Notice

<%# DataBinder.Eval (Container.Data Item, "Applicatio n") = "Notice" %>
= False

<%# DataBinder.Eval (Container.Data Item, trim("Applicati on")) =
trim("Applicati on") %>
= False (this one REALLY has me stumped)

<%# Convert.ToBoole an(DataBinder.E val(Container.D ataItem,
trim("Applicati on")).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 1035
> Maybe the text is "notice" instead of "Notice".

Not that I can tell. This is what is returned:
<%# DataBinder.Eval (Container.Data Item, "Applicatio n") %>
= 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.Data Item, "lastname") = "Fuller"%>' ><%#
DataBinder.Eval (Container.Data Item, "lastname") %></span></li></itemtemplate>
<footertemplate ></ul></footertemplate>
</asp:repeater>

Private conn As New
SqlConnection(C onfigurationSet tings.AppSettin gs("ConnectionS tring"))

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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.ExecuteRead er(CommandBehav ior.CloseConnec tion)

Repeater1.DataS ource = dr
Repeater1.DataB ind()
End Sub

"darrel" <no*****@hotmai l.com> wrote in message
news:ua******** ******@TK2MSFTN GP11.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.Data Item,
"Application"). ToString() = "Notice" %>'>
<custom html>
</span>

...and calling a function:

<%# TestSub(DataBin der.Eval(Contai ner.DataItem, "Application")) %>

Function TestSub(ByVal YourItem as String)
If (YourItem="Noti ce") 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.Data Item, "Applicatio n") %>
= Notice

<%# DataBinder.Eval (Container.Data Item, "Applicatio n") = "Notice" %>
= False

<%# DataBinder.Eval (Container.Data Item, trim("Applicati on")) =
trim("Applicati on") %>
= False (this one REALLY has me stumped)

<%# Convert.ToBoole an(DataBinder.E val(Container.D ataItem,
trim("Applicati on")).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.EventArg s)
Dim strConnect As String
strConnect = ConfigurationSe ttings.AppSetti ngs("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.OleDbConn ection(strConne ct)
Dim objConnect As New System.Data.Ole Db.OleDbConnect ion(strConnect)
objConnect.Open ()
'Dim objCommand As New OleDb.OleDbComm and(strChk, objConnect)
Dim objCommand As New System.Data.Ole Db.OleDbCommand (strChk, objConnect)
Repeater1.DataS ource = objCommand.Exec uteReader()
Repeater1.DataB ind()
Catch objError As Exception
' outMessage.Inne rHtml = "Error accessing Database.<br />"
_
' & objError.Messag e & "<br />" & objError.Source
Exit Sub
End Try

End Sub

Function TestSub(ByVal YourItem as String)
If (YourItem="Noti ce") 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(DataBin der.Eval(Contai ner.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*****@hotmai l.com> wrote in message
news:OR******** ******@TK2MSFTN GP12.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.EventArg s)
Dim strConnect As String
strConnect = ConfigurationSe ttings.AppSetti ngs("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.OleDbConn ection(strConne ct)
Dim objConnect As New System.Data.Ole Db.OleDbConnect ion(strConnect)
objConnect.Open ()
'Dim objCommand As New OleDb.OleDbComm and(strChk, objConnect)
Dim objCommand As New System.Data.Ole Db.OleDbCommand (strChk, objConnect) Repeater1.DataS ource = objCommand.Exec uteReader()
Repeater1.DataB ind()
Catch objError As Exception
' outMessage.Inne rHtml = "Error accessing Database.<br />" _
' & objError.Messag e & "<br />" & objError.Source
Exit Sub
End Try

End Sub

Function TestSub(ByVal YourItem as String)
If (YourItem="Noti ce") 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(DataBin der.Eval(Contai ner.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'...whic h 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
AAAAARRRRRGGGGG GGGGHHHHHHHHHHH HHHHH!

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*****@hotmai l.com> wrote in message
news:Op******** ******@TK2MSFTN GP09.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
2899
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 records for the displaygroup field (an integer datatype). I get an "Either BOF or EOF is True, or the current record has been deleted.." error if i put any type of comparison number (of course MAX is not a vbscript keyword)
9
1478
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 the program doesn't work properly. Does somebody know why? This is the program: <html> <head> <script language="javascript">
5
1878
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 sample hold time data from EPA regulations and spits out when a sample would expire, so we can properly label the thing. The problem is that the .js I have written appears to be doing something unexpected. The Analysis options are presented as...
19
2543
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
2046
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 with null values, use the following expression: "Isnull(Col1,'Null Column') = 'Null Column'" *************************' So I tried like this: mainDataSource.RowFilter = "Gender = 'male' and " & "Isnull(floor,'Null
0
1030
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 to: s="0 Or (1 or 0)" If s Then flag=True Else flag=False End If
21
2422
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 C++ Standard: "" "...sequence of operators and operands that specifies a computation...". That means to me that an expression can be "executed". I am purposely
23
1476
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, (X||Y||Z)); ... or maybe...
3
1538
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' (default not selected for a dropdown list). So far so good...however, although the value=='999' bit works, those fields that post a null or empty value (radio buttons, textareas) don't seem to get picked up. Any ideas on what I'm doing wrong...
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10304
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9114
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.