• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 638
  • Last Modified:

Syntax for ASPX markup to hide control based on NOT of boolean data item

In a repeater, I can use the following to display a control:

<asp:CheckBox ID="chkDelete" Runat="server" Visible='<%# DataBinder.Eval(Container.DataItem, "ShowFlag") %>' />

But what if I have two controls that are mutually exclusive so that one should show and the other should be hidden. For example,

<asp:CheckBox ID="chkDelete" Runat="server" Visible='<%# DataBinder.Eval(Container.DataItem, "ShowFlag") %>' />
<asp:Label ID="lblNothing" Runat="server" Visible='<%# NOT DataBinder.Eval(Container.DataItem, "ShowFlag") %>' >Nothing To Delete</asp:Label>

The last declaration using NOT doesn't work. Is it possible to do this inline?
0
ZekeLA
Asked:
ZekeLA
  • 3
  • 3
  • 2
3 Solutions
 
guru_samiCommented:
My guess would be..
you might try doing that in Code behind ....in ItemDataBound event
0
 
ZekeLAAuthor Commented:
I'm looking for an inline solution. I know how to do it in Code Behind. Does anyone know if inline is possible for my situation?
0
 
hehdaddyCommented:
Have you tried <%# !DataBinder.Eval... ?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ZekeLAAuthor Commented:
Hi HeyDaddy. I'm using VB  ( %@ Control Language="vb" ) and I already tried
  <%# NOT DataBinder.Eval(Container.DataItem  
which is the same but it didn't work.

Thanks anyway.
0
 
hehdaddyCommented:
Try something like this. Please forgive me if the syntax is wrong, I am away from my development machine.

Visible='<%# If Not DataBinder.Eval(Container.DataItem, "ShowFlag") = "True" Then "False" Else "True" End If %>'

or

Visible='<%# DataBinder.Eval(Container.DataItem, "ShowFlag") != "True" ? "False" : "True" %>'
0
 
guru_samiCommented:
This is something worked with C# ..try with VB:

Visible='<%# !Convert.ToBoolean(DataBinder.Eval(Container.DataItem, "Discontinued"))%>'

'Discontinued' is a bit value in Database table.
0
 
guru_samiCommented:
So with VB it will be:
Visible='<%# NOT Convert.ToBoolean(DataBinder.Eval(Container.DataItem, "ShowFlag"))%>'
0
 
ZekeLAAuthor Commented:
Well, the good news is that Convert.ToBoolean works.
The bad news is that my original statement appears to be wrong. <%# NOT DataBinder.Eval(Container.DataItem, "ShowFlag"))%> now works just fine.

I don't know if I had a syntax error originally or if something else was going on. Apologies to everyone. I've increased the points for the effort and spread them to those who had correct answers.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now