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.