更改行或记录的颜色上asp.net C#一个gridview? [英] Change the color of a row or record on a gridview on asp.net c#?

查看:234
本文介绍了更改行或记录的颜色上asp.net C#一个gridview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个表预约的书......我需要做以下...

显示尚未参加但所有的约会(我有一个按钮,以纪念他们为参加)...
如果预约还没有参加,它的日期是今天的日期之前,该行必须出现在红(文字字体颜色)...

所以,我的问题是,我该如何更改特定行的颜色,如果有什么东西,我必须在查询到指定该行都有一个differente颜色?

感谢您

 < ASP:GridView控件ID =grdvEventosVendedor=服务器AllowPaging =真
                的AutoGenerateColumns =FALSE的cellpadding =4的DataKeyNames =idCita
                EmptyDataText =没有干草EVENTOS啪啦埃斯特Vendedor前景色=#333333
                网格线=无AllowSorting =真
                onpageindexchanging =grdvEventosVendedor_PageIndexChanging
                onrowcommand =grdvEventosVendedor_RowCommand
                onsorting =grdvEventosVendedor_SortingCELLSPACING =1
                onrowdatabound =grdvEventosVendedor_RowDataBound>
                < AlternatingRowStyle背景色=白前景色=#284775/>                <柱体和GT;
                    < ASP:的TemplateField的HeaderText =ItemStyle-WIDTH =35px>
                        <&ItemTemplate中GT;
                            < ASP:ImageButton的ID =imgBtnEdicEvento=服务器
                                CommandArgument ='<%#的eval(idCita)%>'的CommandName =Edicion
                                HEIGHT =32PX的ImageUrl =〜/ IMG / pencil_32.pngWIDTH =32PX/>
                        < / ItemTemplate中>
                    < / ASP:的TemplateField>                    < ASP:的TemplateField的HeaderText =ItemStyle-WIDTH =35px>
                        <&ItemTemplate中GT;
                            < ASP:ImageButton的ID =imgBtnDelete=服务器
                                的CommandName =Borrar
                                的ImageUrl =〜/ IMG / 1385_Disable_16x16_72.png
                                的OnClientClick =返回确认('¿Desea eliminar EL registro?');
                                CommandArgument ='<%#的eval(idCita)%>' />
                        < / ItemTemplate中>
                    < / ASP:的TemplateField>                    < ASP:BoundField的数据字段=Cliente的HeaderText =ClienteInsertVisible =FALSE只读=真SORTEX pression =ClienteItemStyle-WIDTH =50像素/>
                    < ASP:BoundField的数据字段=EM preSA的HeaderText =EM preSAInsertVisible =FALSE只读=真SORTEX pression =EM preSAItemStyle宽度= 50像素/>
                    < ASP:BoundField的数据字段=Telefono的HeaderText =TelefonoInsertVisible =FALSE只读=真SORTEX pression =TelefonoItemStyle-WIDTH =50像素/>
                    < ASP:BoundField的数据字段=Nextel公司的HeaderText =Nextel的InsertVisible =FALSE只读=真SORTEX pression =Nextel的ItemStyle-WIDTH =50像素/>
                    < ASP:BoundField的数据字段=TIPO的HeaderText =TIPOInsertVisible =FALSE只读=真SORTEX pression =TIPOItemStyle-WIDTH =50像素/>
                    < ASP:BoundField的数据字段=Descripcion的HeaderText =DescripcionInsertVisible =FALSE只读=真SORTEX pression =DescripcionItemStyle-WIDTH =100像素/>                    < ASP:的TemplateField的HeaderText =出生日期SORTEX pression =出生日期ItemStyle-WIDTH =50像素>
                        <&ItemTemplate中GT;
                            <%#DataBinder.Eval的(的Container.DataItem,出生日期,{0:DD / MM / YYYY})%GT;
                        < / ItemTemplate中>                        <&EditItemTemplate的GT;
                            < ASP:文本框ID =tbxFecha=服务器文本='<%#绑定(出生日期,{0:DD / MM / YYYY})%GT;'的ValidationGroup =gpEdicionAgenda>
                            < / ASP:文本框>
                        < / EditItemTemplate中>
                    < / ASP:的TemplateField>                    < ASP:BoundField的数据字段=HoraInicio的HeaderText =霍拉InsertVisible =FALSE只读=真SORTEX pression =HoraInicioItemStyle-WIDTH =50像素/>
                    < ASP:BoundField的数据字段=卢格的HeaderText =卢格InsertVisible =FALSE只读=真SORTEX pression =卢格ItemStyle-WIDTH =50像素/>
                    < ASP:BoundField的数据字段=埃斯塔的HeaderText =埃斯塔InsertVisible =FALSE只读=真SORTEX pression =埃斯塔ItemStyle-WIDTH =50像素/>                    < ASP:的TemplateField的HeaderText =AtenderItemStyle-WIDTH =35px>
                        <&ItemTemplate中GT;
                            < ASP:ImageButton的ID =imgBtnAtender=服务器
                                CommandArgument ='<%#的eval(idCita)%>'的CommandName =Atender
                                的ImageUrl =〜/ IMG / activar.pngWIDTH =16像素HEIGHT =16像素
                                的OnClientClick =返回确认('¿Desea marcar科莫atendido埃斯特registro?'); />
                        < / ItemTemplate中>
                    < / ASP:的TemplateField>                    < ASP:的TemplateField的HeaderText =CRMItemStyle-WIDTH =35px>
                        <&ItemTemplate中GT;
                            < ASP:ImageButton的ID =imgBtnCRM=服务器
                                CommandArgument ='<%#的eval(IdCliente)%>'的CommandName =CRM
                                的ImageUrl =〜/ IMG / go.gifWIDTH =16像素HEIGHT =16像素/>
                        < / ItemTemplate中>
                    < / ASP:的TemplateField>                    < ASP:的TemplateField的HeaderText =VMItemStyle-WIDTH =35px>
                        <&ItemTemplate中GT;
                            < ASP:ImageButton的ID =imgBtnVerMas=服务器
                                CommandArgument ='<%#的eval(IdCliente)%>'的CommandName =VerMas
                                的ImageUrl =〜/ IMG / search.pngWIDTH =16像素HEIGHT =16像素/>
                        < / ItemTemplate中>
                    < / ASP:的TemplateField>
                < /专栏>                < EditRowStyle背景色=#999999FONT-SIZE =小/>
                < FooterStyle背景色=#5D7B9DFONT-粗体=真前景色=白/>
                < HeaderStyle背景色=#5D7B9DFONT-粗体=真前景色=白FONT-SIZE =较大/>
                < PagerStyle背景色=#284775前景色=白Horizo​​ntalAlign =中心/>
                < RowStyle的BackColor =#F7F6F3前景色=#333333Horizo​​ntalAlign =中心FONT-SIZE =小/>
                < SelectedRowStyle背景色=#E2DED6FONT-粗体=真前景色=#333333/>
                < SortedAscendingCellStyle背景色=#E9E7E2/>
                < SortedAscendingHeaderStyle背景色=#506C8C/>
                < SortedDescendingCellStyle背景色=#FFFDF8/>
                < SortedDescendingHeaderStyle背景色=#6F8DAE/>
            < / ASP:GridView的>


解决方案

您可以在您可以在 grdvEventosVendedor_RowDataBound GridView控件的事件

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

或者,你可以使用

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

您可以像这样来实现上面的东西:

 保护无效grdvEventosVendedor_RowDataBound(对象发件人,GridViewRowEventArgs E)
{
  如果(e.Row.RowType = DataControlRowType.DataRow)
  {
      如果(put_your_condition_here)
      {
           e.Row.BackColor = Drawing.Color.Red;
           ////也可以通过这样指定颜色:e.Row.BackColor = Color.FromName(#FFOOOO);
      }
  }
}

I am making a table for an appointment book... and I need to do the following...

Display all appointments that have not been attended yet (I have a button to mark them as attended)... If an appointment has not been attended and it's date is before today's date, that row must appear in red (the text font color)...

So my questions are, how do I change the color of specific rows, AND if there's something that I must get in the query to specify that this row has to have a differente color?

Thank You

<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>

解决方案

You can change the color of row by specifying your color in Backcolor attribute of row which you can specify in grdvEventosVendedor_RowDataBound event of gridview

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

or, you can use

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

You can do like this to implement above things:

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");
      }
  }
}

这篇关于更改行或记录的颜色上asp.net C#一个gridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆