1
I’m making a system ASPNET c# WEBFORM
, and food a REPEATER
with information coming from the database.
I would like a certain cell to have a certain color, according to information coming from the database.
Example: Column CodStatus
, if it’s approved, the cell turns green and if it is flunked the cell turns red.
Follows the code:
Listarproposta.aspx
<asp:Repeater ID="rptProposta" runat="server">
<HeaderTemplate>
<table id="tblCustomers" class="footable" border="0" >
<thead>
<tr>
<th data-class="expand">
<font ><b>Código</b></font>
</th>
<th data-class="expand">
<font ><b>Situação </b></font>
</th>
<th scope="col">
<font ><b>Cliente</b></font>
</th>
<th style="display: table-cell;" data-hide="phone">
<font ><b>Valor Proposta</b></font>
</th>
<th class="text-center" style="display: table-cell;" data-hide="phone">
<font ><b>Ação</b></font>
</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr style="color:red">
<td >
<%# DataBinder.Eval(Container.DataItem, "codproposta") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "situacao") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "cliente") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "valortotal") %>
</td>
<td>
<asp:ImageButton ID="imbtnAlterar" ImageUrl="~/img/editar.ico" Width="30px" Height="30px" runat="server" CommandArgument='<%# Eval("codproposta") %>' />
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/img/excluir.ico" Width="30px" Height="30px" CommandArgument='<%# Eval("codproposta") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
The way I carry REPEATER
Listarproposta.aspx.Cs
protected void CarregarProposta()
{
Proposta p = new Proposta();
p.codproposta = 0;
SqlDataReader drProposta = p.ListarProposta(p);
rptProposta.DataSource = drProposta;
rptProposta.DataBind();
}
I was going to post almost exactly the same thing, only I had created the styles as . approved and .reproved... so I wouldn’t even need the if in Bind
– Leandro Angelo
I understood your idea is really good, I hadn’t thought about it @Leandroangelo
– novic
@Leandroangelo made the change.
– novic
Thank you very much. This is exactly what I wanted. It worked correctly.
– Rodrigo Storti de Oliveira