Link to home
Start Free TrialLog in
Avatar of David Pickart
David PickartFlag for United States of America

asked on

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

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.
Avatar of rodmjay
rodmjay
Flag of United States of America image


try <%# instead of <%
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")) #>' />
if you are using asp.net 2.0 you can just use Eval instead of DataBinder.Eval(Container.DataItem, "StartTime")
ASKER CERTIFIED SOLUTION
Avatar of Hamed Zaghaghi
Hamed Zaghaghi
Flag of Iran, Islamic Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David Pickart

ASKER

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.