简体   繁体   中英

Error while Embedding Xpath Code and Inline Server Tags

Grid View template field -

<% if ((Convert.ToInt64(XPath("NoOfGuests")) < 0))
      { %>
      <asp:ImageButton ID="imgbtnAddResByList" 
                       runat="server" 
                       ImageUrl="~/images/btn-addResByList.PNG" />
      <asp:ImageButton ID="imgbtnCloseResByList" 
                       runat="server" 
                       ImageUrl="~/images/imgdelete.jpg" />
    <%} %>

this throws a runtime error "Databinder exception...". I think it is coming because I have not used # in inline code. But I dont know how and where. My concern is I dont want to display there two image buttons when XPath("NoOfGuests") < 0 but I dont want to do this in OnDataBound or OnRowCreated because of performance issue. Is there any other way??

Would it work to evaluate the visibility of each button with the condition? For instance:

<asp:ImageButton ID="imgbtnAddResByList" runat="server" 
  ImageUrl="~/images/btn-addResByList.PNG"
  Visible='<%# If((Convert.ToInt64(XPath("NoOfGuests")) < 0), "False", "True") %>' />
<asp:ImageButton ID="imgbtnCloseResByList" runat="server" 
  ImageUrl="~/images/imgdelete.jpg"
  Visible='<%# If((Convert.ToInt64(XPath("NoOfGuests")) < 0), "False", "True") %>' />

Also, it looks like you haven't specified your conditions for your If statement, so if you wanted to stick with what you've got, you might try something like:

<%# If((Convert.ToInt64(XPath("NoOfGuests")) < 0), "{", "") %>
  <asp:ImageButton ID="imgbtnAddResByList" 
                   runat="server" 
                   ImageUrl="~/images/btn-addResByList.PNG" />
  <asp:ImageButton ID="imgbtnCloseResByList" 
                   runat="server" 
                   ImageUrl="~/images/imgdelete.jpg" />
<%# If((Convert.ToInt64(XPath("NoOfGuests")) < 0), "}", "") %>

Although to be honest, I don't think that will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM