David Pickart
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(C ontainer.D ataItem, "StoreArrival")) Or IsDBNull(DataBinder.Eval(C ontainer.D ataItem, "StoreDepart")) Or IsDBNull(DataBinder.Eval(C ontainer.D ataItem, "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.
<% If (IsDBNull(DataBinder.Eval(
<asp:Label ID="Label6" Text = '' runat="Server" />
<% Else%>
<asp:label ID="label16" runat="server" Text='<%# DataBinder.Eval(Container.
<% 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.
try an iif statement instead
<asp:label id="label16" runat="Server" text='<%# IIF(IsDBNull(DataBinder.Ev al(Contain er.DataIte m, "StartTime")) Or IsDBNull(DataBinder.Eval(C ontainer.D ataItem, "StoreArrival")) Or IsDBNull(DataBinder.Eval(C ontainer.D ataItem, "StoreDepart")) Or IsDBNull(DataBinder.Eval(C ontainer.D ataItem, "EndofDay")), "", Eval("StartTime")) #>' />
<asp:label id="label16" runat="Server" text='<%# IIF(IsDBNull(DataBinder.Ev
if you are using asp.net 2.0 you can just use Eval instead of DataBinder.Eval(Container. DataItem, "StartTime")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
try <%# instead of <%