|
<< Click to Display Table of Contents >> GridView - Coluna com imagem condicional ao conteúdo |
![]() ![]()
|
Default.aspx
<asp:TemplateField>
<ItemTemplate>
<center>
<asp:ImageButton ID="btnConcluir" runat="server"></asp:ImageButton>
</center>
</ItemTemplate>
</asp:TemplateField>
Default.aspx.cs
protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
// quando montar as linhas do tipo DADOS
if (e.Row.RowType == DataControlRowType.DataRow)
{
// pega os campos tipo e propriedade
string status = DataBinder.Eval(e.Row.DataItem, "status").ToString();
// cores para aprovação
if (status == "Para aprovação")
e.Row.Cells[3].ForeColor = Color.Fuchsia;
// mostra o icone "concluir tarefa"
ImageButton ib = (ImageButton)e.Row.FindControl("btnConcluir");
if (ib != null)
{
// cores para aprovação
if (status == "Concluída")
{
ib.ImageUrl = "visual/concluido.jpg";
ib.ToolTip = "Concluir tarefa";
ib.CommandName = "Concluir";
ib.Visible = true;
}
else
if (status == "Pendente")
{
ib.ImageUrl = "visual/pendente.jpg";
ib.ToolTip = "Abrir tarefa";
ib.CommandName = "Abrir";
ib.Visible = true;
}
else
ib.Visible = false;
}
}