Reputation: 1710
I have read through the various topics and found none that assisted me in my situation.
Based on whether it is 1 or 0 for my sold variable, i want to be able to show or hide a button accordingly.
I did the following but I am getting a server tag not well formed error and despite changing the quotes ' and " (which i knew wouldn't help), it still doesn't solve the error.
<asp:Button ID="btnMarkAsSold" OnClick="btnWantSell" runat="server" Text="Mark as sold" class="btn btn-warning btn-block higher bold" <%#(Eval("Sold").ToString() == "1" ? "style='display:none'" : String.Empty) %> />
<asp:Button ID="btnSold" runat="server" Text="SOLD" class="btn btn-danger btn-block higher bold" <%#(Eval("Sold").ToString() == "0" ? "style='display:none'" : String.Empty) %> />
Upvotes: 1
Views: 766
Reputation: 3800
Tested and below is working
The problem is style=display:none
. Create a class like hidden
and update your button as:
<asp:Button ID="btnSold" runat="server" Text="SOLD" class='btn btn-danger btn-block higher bold <%#(Eval("Sold").ToString() == "0" ? "hidden" : String.Empty) %>' />
<asp:Button ID="btnMarkAsSold" OnClick="btnWantSell" runat="server" Text="Mark as sold" class='btn btn-warning btn-block higher bold <%#(Eval("Sold").ToString() == "1" ? "hidden" : String.Empty) %>' />
CSS
hidden{ display:none;}
Visible property
To use Visible
property of button as suggested in @Mahmood's answer
<asp:Button ID="btnSold" runat="server" Text="SOLD" class="btn btn-danger btn-block higher bold" Visible="<%# Eval("Sold").ToString() == "0" ? false : true %>" />
Upvotes: 2
Reputation: 8265
You can not use inline server tag directly in a server control. However you can do so inside an attribute:
<asp:Button ID="btnSold" runat="server" Text="SOLD" class="btn btn-danger btn-block higher bold" Visible="<%# Eval("Sold").ToString() == "0" ? false : true %>" />
<asp:Button ID="btnMarkAsSold" OnClick="btnWantSell" runat="server" Text="Mark as sold" class="btn btn-warning btn-block higher bold" Visible="<%#Eval("Sold").ToString() == "1" ? false : true %> />
Upvotes: 2