c# - 在 asp.net c# 的 gridview 上更改行或记录的颜色?

标签 c# asp.net gridview colors row

我正在为预约簿制作表格...我需要执行以下操作...

显示所有尚未参加的约会(我有一个按钮将它们标记为已参加)... 如果尚未参加约会并且约会日期早于今天的日期,则该行必须显示为红色(文本字体颜色)...

所以我的问题是,如何更改特定行的颜色,以及是否必须在查询中获取某些内容以指定该行必须具有不同的颜色?

谢谢

<asp:GridView ID="grdvEventosVendedor" runat="server" AllowPaging="True" 
                AutoGenerateColumns="False" CellPadding="4" DatakeyNames="idCita"
                EmptyDataText="No Hay Eventos Para Este Vendedor" ForeColor="#333333" 
                GridLines="None" AllowSorting="True"
                onpageindexchanging="grdvEventosVendedor_PageIndexChanging" 
                onrowcommand="grdvEventosVendedor_RowCommand" 
                onsorting="grdvEventosVendedor_Sorting" CellSpacing="1" 
                onrowdatabound="grdvEventosVendedor_RowDataBound" >
                <AlternatingRowStyle BackColor="White" ForeColor="#284775"/>

                <Columns>
                    <asp:TemplateField HeaderText="" ItemStyle-Width="35px">
                        <ItemTemplate>
                            <asp:ImageButton ID="imgBtnEdicEvento" runat="server" 
                                CommandArgument='<%# Eval("idCita")%>' CommandName="Edicion" 
                                Height="32px" ImageUrl="~/img/pencil_32.png" Width="32px" />
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="" ItemStyle-Width="35px">
                        <ItemTemplate>
                            <asp:ImageButton ID="imgBtnDelete" runat="server"
                                CommandName="Borrar" 
                                ImageUrl="~/img/1385_Disable_16x16_72.png" 
                                onclientclick="return confirm('¿Desea eliminar el registro?');" 
                                CommandArgument='<%# Eval("idCita")%>' />
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:BoundField DataField="Cliente" HeaderText="Cliente" InsertVisible="False" ReadOnly="True" SortExpression="Cliente" ItemStyle-Width="50px" />
                    <asp:BoundField DataField="Empresa" HeaderText="Empresa" InsertVisible="False" ReadOnly="True" SortExpression="Empresa" ItemStyle-Width="50px"/>
                    <asp:BoundField DataField="Telefono" HeaderText="Telefono" InsertVisible="False" ReadOnly="True" SortExpression="Telefono" ItemStyle-Width="50px"/>
                    <asp:BoundField DataField="Nextel" HeaderText="Nextel" InsertVisible="False" ReadOnly="True" SortExpression="Nextel" ItemStyle-Width="50px"/>
                    <asp:BoundField DataField="Tipo" HeaderText="Tipo" InsertVisible="False" ReadOnly="True" SortExpression="Tipo" ItemStyle-Width="50px"/>
                    <asp:BoundField DataField="Descripcion" HeaderText="Descripcion" InsertVisible="False" ReadOnly="True" SortExpression="Descripcion" ItemStyle-Width="100px"/>

                    <asp:TemplateField HeaderText="Fecha" SortExpression="Fecha" ItemStyle-Width="50px">
                        <ItemTemplate>                                            
                            <%# DataBinder.Eval(Container.DataItem, "Fecha", "{0:dd/MM/yyyy}")%>
                        </ItemTemplate>

                        <EditItemTemplate>                                        
                            <asp:TextBox ID="tbxFecha"  runat="server" Text='<%#Bind("Fecha","{0:dd/MM/yyyy}") %>' ValidationGroup="gpEdicionAgenda">
                            </asp:TextBox>
                        </EditItemTemplate>
                    </asp:TemplateField>

                    <asp:BoundField DataField="HoraInicio" HeaderText="Hora" InsertVisible="False" ReadOnly="True" SortExpression="HoraInicio" ItemStyle-Width="50px"/>
                    <asp:BoundField DataField="Lugar" HeaderText="Lugar" InsertVisible="False" ReadOnly="True" SortExpression="Lugar" ItemStyle-Width="50px"/>
                    <asp:BoundField DataField="Estado" HeaderText="Estado" InsertVisible="False" ReadOnly="True" SortExpression="Estado" ItemStyle-Width="50px"/>

                    <asp:TemplateField HeaderText="Atender" ItemStyle-Width="35px">
                        <ItemTemplate>
                            <asp:ImageButton ID="imgBtnAtender" runat="server"
                                CommandArgument='<%# Eval("idCita")%>' CommandName="Atender" 
                                ImageUrl="~/img/activar.png" Width="16px" Height="16px" 
                                onclientclick="return confirm('¿Desea marcar como atendido este registro?');" />
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="CRM" ItemStyle-Width="35px">
                        <ItemTemplate>
                            <asp:ImageButton ID="imgBtnCRM" runat="server"
                                CommandArgument='<%# Eval("IdCliente")%>' CommandName="CRM" 
                                ImageUrl="~/img/go.gif" Width="16px" Height="16px" />
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="VM" ItemStyle-Width="35px">
                        <ItemTemplate>
                            <asp:ImageButton ID="imgBtnVerMas" runat="server"
                                CommandArgument='<%# Eval("IdCliente")%>' CommandName="VerMas" 
                                ImageUrl="~/img/search.png" Width="16px" Height="16px" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>

                <EditRowStyle BackColor="#999999" Font-Size="Small" />
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Font-Size="Larger" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Center" Font-Size="Small" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#E9E7E2" />
                <SortedAscendingHeaderStyle BackColor="#506C8C" />
                <SortedDescendingCellStyle BackColor="#FFFDF8" />
                <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
            </asp:GridView>

最佳答案

您可以通过在行的 Backcolor 属性中指定您的颜色来更改行的颜色,您可以在 gridview 的 grdvEventosVendedor_RowDataBound 事件中指定

 e.Row.BackColor = Drawing.Color.Red;

或者,你可以使用

`e.Row.BackColor = Color.FromName("#FFOOOO");` 

你可以这样做来实现上面的东西:

protected void grdvEventosVendedor_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType = DataControlRowType.DataRow)
  {
      if(put_your_condition_here)
      {
           e.Row.BackColor = Drawing.Color.Red;
           //// or you can assign color by doing this: e.Row.BackColor = Color.FromName("#FFOOOO");
      }
  }
}

关于c# - 在 asp.net c# 的 gridview 上更改行或记录的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11974025/

相关文章:

c# - 在 asp.net 中处理危险字符的最佳做法是什么?

c# - 在格式字符串(又称插值字符串)中使用三进制运算符时出错

c# - 为什么 C# 可以在运行时处理这种明显愚蠢的对象提升?

asp.net - 在 ASP.NET MVC 中设置空响应的 Content-Type

asp.net - 从异步调用加载 ASP.NET GridView

c# - 在 Windows Phone 8.1 上运行频繁的后台任务

ASP.NET 帮助! FireFox 正在吃我的 cookies !

asp.net 线程评论?

c# - EventArgs VS GridViewRowEventArgs

listview - 使用不同类型的组件 react native ListView