Inline Boolean Condition Not Being Met in ASP DataGrid

I inherited a web application written in c# which contains a datagrid. This dg has ItemTemplates, one of which has the following code:

				<asp:textbox id="NewQuantity" onkeydown="processKeystroke(event);" runat="server" width="35px" columns="4" maxlength="3" text="" cssclass="EditTextBox" 
				Visible='<%# (DataBinder.Eval(Container.DataItem, "ProductID") == "") || (DataBinder.Eval(Container.DataItem, "ProductID") == DBNull.Value)? false:true  %>'>

Open in new window

If I understand the code correctly, the textbox will either be Visible or not Visible dependant on whether or not the ProductID is Empty || Null.

Trouble is, the condition always seems to be 'True' even when the data is an Empty String or Null.

An example of the data from my db:
PL_ID      ProductID      ModelName
14292324                 ***MELONS***

What could be causing the condition to always result in True?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HainKurtSr. System AnalystCommented:
lets try something

Visible='<%# false %>'

what happens if you do this?
HainKurtSr. System AnalystCommented:
or just try this

Visible='<%# (DataBinder.Eval(Container.DataItem, "ProductID") == "") ? false:true  %>
jsvb1977Author Commented:
I tried 3 scenerios:

1. Visible='<%# false %>'
    - Resulted in all textboxes NOT Visible

2. Visible='<%# (DataBinder.Eval(Container.DataItem, "ProductID") == "") ? false:true  %>
    - Resulted in all textboxes Visible

3. Visible='<%# (DataBinder.Eval(Container.DataItem, "ProductID") == DBNull.Value)? false:true  %>'>
    - Resulted in all textboxes Visible
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

HainKurtSr. System AnalystCommented:

ok, try

Visible='<%# true %>' mydata='<%# DataBinder.Eval(Container.DataItem, "ProductID")%>'

and check view source of page for mydata
what do you see...
HainKurtSr. System AnalystCommented:
looks like it is working and your records have all ProductID populated...
maybe it is not null, maybe it is some space, try trim

 Visible='<%# (DataBinder.Eval(Container.DataItem, "ProductID").Trim() == "") ? false:true  %>
jsvb1977Author Commented:
Good call... but this:

Compiler Error Message: CS0117: 'object' does not contain a definition for 'Trim'

So i wrapped it in a convert.tostring(), but i am still getting the error:

Here is the code:
Visible='<%# Convert.ToString((DataBinder.Eval(Container.DataItem, "ProductID")).Trim() == "") || (DataBinder.Eval(Container.DataItem, "ProductID") == DBNull.Value)? false:true  %>'>

Maybe the convert.tostring needs to be somewhere else?
jsvb1977Author Commented:
Ahhh, that was it...

Visible='<%# (Convert.ToString(DataBinder.Eval(Container.DataItem, "ProductID")).Trim() == "") ? false:true  %>'>

Open in new window

HainKurtSr. System AnalystCommented:
what about this

Visible='<%# (DataBinder.Eval(Container.DataItem, "ProductID").ToString().Trim() == "") ? false:true  %>'>

is trim solving your issues?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jsvb1977Author Commented:
Yes, using trim with the convert.tostring is what did it. Like this:

Visible='<%# (Convert.ToString(DataBinder.Eval(Container.DataItem, "ProductID")).Trim() == "") ? false:true  %>'>
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.