Solved

Cannot get IF statement to work inside asp.net page.

Posted on 2006-07-12
5
702 Views
Last Modified: 2012-05-05
I have the following code.

 <% If (IsDBNull(DataBinder.Eval(Container.DataItem, "StartTime")) Or IsDBNull(DataBinder.Eval(Container.DataItem, "StoreArrival")) Or IsDBNull(DataBinder.Eval(Container.DataItem, "StoreDepart")) Or IsDBNull(DataBinder.Eval(Container.DataItem, "EndofDay"))) Then%>
             <asp:Label ID="Label6" Text = '' runat="Server" />
<% Else%>
              <asp:label ID="label16" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "StartTime") %>' />
<%  End If%>

The container.dataitem method works fine outside the if, but once I place it inside, it becomes unrecognizable.  I just want to see if

<%# DataBinder.Eval(Container.DataItem, "StartTime") %> is empty,  if it's not I run a function, if it it is I enter a 0 in a gridview column.
0
Comment
Question by:Break40
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 8

Expert Comment

by:rodmjay
ID: 17093951

try <%# instead of <%
0
 
LVL 8

Expert Comment

by:rodmjay
ID: 17093968
try an iif statement instead

<asp:label id="label16" runat="Server" text='<%# IIF(IsDBNull(DataBinder.Eval(Container.DataItem, "StartTime")) Or IsDBNull(DataBinder.Eval(Container.DataItem, "StoreArrival")) Or IsDBNull(DataBinder.Eval(Container.DataItem, "StoreDepart")) Or IsDBNull(DataBinder.Eval(Container.DataItem, "EndofDay")), "", Eval("StartTime")) #>' />
0
 
LVL 8

Expert Comment

by:rodmjay
ID: 17094043
if you are using asp.net 2.0 you can just use Eval instead of DataBinder.Eval(Container.DataItem, "StartTime")
0
 
LVL 9

Accepted Solution

by:
zaghaghi earned 500 total points
ID: 17094196
if you want to check the StartTime, why did you check another fileds in data Item?

just check that one you want

<% If IsDBNull(DataBinder.Eval(Container.DataItem, "StartTime")) Then%>
             <asp:Label ID="Label6" Text = '' runat="Server" />
<% Else%>
              <asp:label ID="label16" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "StartTime") %>' />
<%  End If%>
0
 

Author Comment

by:Break40
ID: 17138291
I checked the others because eventually I need them as well, I just tried to simplify it for the solution.  WHen I run code like you sugested I keep getting the null error because the bound column may be empty if the person did not work that day and no data is in that field for that row.

When I place you code in page the "Container" method is not recognized.  I solved the problem, but would still like to know why the container methode fails inside the if statement.
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question