How to change the background color in repeater control based on the values

Welcome to Programming Tutorial official website. Today - we are going to cover how to solve / find the solution of this error How to change the background color in repeater control based on the values on this date .

Aspx code:

<div class="col-3 col-m-12">
    <div class="OrderPageContent" >            
      <h5 style="margin-left:20px">Status :<a style="font-weight:bold;color:green"> 
         <asp:Button ID="Button1" CssClass="YordersButton"  Text='<%#Eval("PaymentStatus") %>' runat="server" CommandName="Button1"></asp:Button></a></h5>
                         
</div>
  </div>

Please someone help , i have different type of paymentstatus for ex : Payment not verified, Payment Verified . If my paymentstatus = Payment Not verified i want to make the button background color as red, if Paymentststatus = Payment verified then then button background color as green.

Answer

Try something similar to below:

<%
if(Eval("PaymentStatus") = "Payment Verified")
{%>

Status :<a style="font-weight:bold;color:green"> 
         <asp:Button ID="Button1" CssClass="YordersButton"  Text='<%#Eval("PaymentStatus") %>' runat="server" CommandName="Button1"></asp:Button></a>

<% } 
else 
{
%>
Status :<a style="font-weight:bold;color:red"> 
         <asp:Button ID="Button1" CssClass="YordersButton"  Text='<%#Eval("PaymentStatus") %>' runat="server" CommandName="Button1"></asp:Button></a>
<% } %>