Note that there are some explanatory texts on larger screens.

plurals
  1. POData Binding in if statements
    primarykey
    data
    text
    <p>In an aspx page i have:</p> <pre><code>&lt;asp:HyperLink ID="HyperLink" runat="server" style="cursor:pointer; text-decoration:none;" NavigateUrl='&lt;%#String.Format("~/storefront.aspx?CatalogID={0}",Eval("CatalogID"))%&gt;'&gt; &lt;asp:Label id="lblCustItem" Runat="server" Text='&lt;%# DataBinder.Eval(Container.DataItem, "CustItem")%&gt;' width="15%"&gt; &lt;/asp:Label&gt; &lt;/asp:HyperLink&gt; </code></pre> <p>And now I am trying to do:</p> <pre><code>&lt;%if (Eval("Integration").ToString() == "Y") { %&gt; &lt;asp:HyperLink ID="HyperLink1" runat="server" style="cursor:pointer; text-decoration:none;" NavigateUrl='&lt;%#String.Format("~/integration/vendorframe.aspx?CatalogID={0}",Eval("CatalogID"))%&gt;'&gt; &lt;asp:Label id="CustItemlbl" Runat="server" Text='&lt;%# DataBinder.Eval(Container.DataItem, "CustItem")%&gt;' width="15%"&gt; &lt;/asp:Label&gt; &lt;/asp:HyperLink&gt; &lt;%} %&gt; &lt;%else { %&gt; &lt;asp:HyperLink ID="HyperLink" runat="server" style="cursor:pointer; text-decoration:none;" NavigateUrl='&lt;%#String.Format("~/storefront.aspx?CatalogID={0}",Eval("CatalogID"))%&gt;'&gt; &lt;asp:Label id="lblCustItem" Runat="server" Text='&lt;%# DataBinder.Eval(Container.DataItem, "CustItem")%&gt;' width="15%"&gt; &lt;/asp:Label&gt; &lt;/asp:HyperLink&gt; &lt;%} %&gt; </code></pre> <p>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.</p> <p>Error Message: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload