In an aspx page i have:
<asp:HyperLink ID="HyperLink" runat="server" style="cursor:pointer; text-decoration:none;" NavigateUrl='<%#String.Format("~/storefront.aspx?CatalogID={0}",Eval("CatalogID"))%>'>
<asp:Label id="lblCustItem" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CustItem")%>' width="15%">
</asp:Label>
</asp:HyperLink>
And now I am trying to do:
<%if (Eval("Integration").ToString() == "Y")
{ %>
<asp:HyperLink ID="HyperLink1" runat="server" style="cursor:pointer; text-decoration:none;" NavigateUrl='<%#String.Format("~/integration/vendorframe.aspx?CatalogID={0}",Eval("CatalogID"))%>'>
<asp:Label id="CustItemlbl" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CustItem")%>' width="15%">
</asp:Label>
</asp:HyperLink>
<%} %>
<%else
{ %>
<asp:HyperLink ID="HyperLink" runat="server" style="cursor:pointer; text-decoration:none;" NavigateUrl='<%#String.Format("~/storefront.aspx?CatalogID={0}",Eval("CatalogID"))%>'>
<asp:Label id="lblCustItem" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CustItem")%>' width="15%">
</asp:Label>
</asp:HyperLink>
<%} %>
the page errors out on the second segment of code. So my question is, am i doing something wrong, and is there a better way to use an if statement, like the conditional if, but i do need to run a new instance of string.format thats why I was thinking that wasn’t an option.
Error Message:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
One solution is to use an Inline If:
It’s not pretty, but it’ll get the job done.