?
Solved

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

Posted on 2006-07-12
5
Medium Priority
?
711 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 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