Solved

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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