Solved

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

Posted on 2006-07-12
5
694 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
  • 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

709 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now