Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8416187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:40:32+00:00 2026-06-10T01:40:32+00:00

I have a gridview which I change some of the rows colors after using

  • 0

I have a gridview which I change some of the rows colors after using RowDataBound….

Here’s my gridview

<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="150px"/>

                    <asp:TemplateField HeaderText="Fecha" SortExpression="Fecha" ItemStyle-Width="50px">
                        <ItemTemplate>
                            <asp:Label ID="lblFecha" runat="server" Text='<%#Bind("Fecha", "{0:dd/MM/yyyy}")%>'>
                            </asp:Label>
                        </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="Estado" ItemStyle-Width="50px">
                        <ItemTemplate>
                            <asp:DropDownList ID="dpdListEstado" runat="server" OnSelectedIndexChanged="dpdListEstado_SelectedIndexChanged" AutoPostBack="True" CommandArgument="">
                                <asp:ListItem>Pendiente</asp:ListItem>
                                <asp:ListItem>Atendido</asp:ListItem>
                            </asp:DropDownList>
                        </ItemTemplate>
                    </asp:TemplateField>--%>

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

in my cs I have…

    private static string strColorUrgente = "#FF525D";
    private static string strColorEnCurso = "#FFDE00";
    private static string strColorHoy = "#3ECF00";

and here’s the rowbounddata function

protected void grdvEventosVendedor_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex >= 0 && e.Row.Cells[11].Text == "Pendiente")
        {
            string strFecha = (e.Row.FindControl("lblFecha") as Label).Text;
            int intYear = Convert.ToInt32(strFecha.Split('/')[2]);
            int intMonth = Convert.ToInt32(strFecha.Split('/')[1]);
            int intDay = Convert.ToInt32(strFecha.Split('/')[0]);
            DateTime dtmFecha = new DateTime(intYear, intMonth, intDay);

            if (dtmFecha < DateTime.Today)
            {
                e.Row.BackColor = Color.FromName(strColorUrgente);
            }

            else if (dtmFecha == DateTime.Today)
            {
                DateTime dtmHoraInicio = Convert.ToDateTime(e.Row.Cells[9].Text);

                if (dtmHoraInicio > DateTime.Now)
                {
                    e.Row.BackColor = Color.FromName(strColorHoy);
                }

                else
                {
                    e.Row.BackColor = Color.FromName(strColorEnCurso);
                }
            }
        }
    }

Whenever I enter to this page or I use a search engine, I refresh the gridview with a datasource, and of course, the RowDataBound is triggered… and eventually some of the rows’ colors will be changed…

You’ll notice that in the gridview, on the last column there’s a button called imgBtnVerMas…

When pressed, it triggers the following function

string strMensaje = "";

        try
        {
            //Method that brings back data from a specific client (returns a datatable)
            //intIdCliente was defined in the CommandArgument
            DataTable dtDatosCliente = ConexionBD.GetInstanciaConexionBD().GetClienteEspecifico2(intIdCliente);
            //Assigning to a string a message that needs info from the previous datatable
            strMensaje += "DATOS DEL CLIENTE\\n\\nNombre:\\t" + dtDatosCliente.Rows[0]["Cliente"] + "\\nEmpresa: " + dtDatosCliente.Rows[0]["Empresa"];
        }

        catch
        {
            if (strMensaje == "")
            {
                strMensaje = "Hubo Un Error Al Traer Los Datos Del Cliente";
            }

            else
            {
                strMensaje += "\n\nERROR!!!!!!!";
            }
        }

        ClientScript.RegisterStartupScript(this.GetType(), "Mensaje", "alert('" + strMensaje + "');", true);

Afterwards, the message is displayed, however, all of the rows colors dissapear… I was wondering… how can I keep the colors of the gridview’s rows even after a postback…

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:40:33+00:00Added an answer on June 10, 2026 at 1:40 am

    You need to set your colors on the event of onprerender and not on RowDataBound, so set the event on GridView

    onprerender="gvMyLista_PreRender"
    

    and on code behind

    protected void gvMyLista_PreRender(object sender, EventArgs e)
    {
       // loop your data, and fix your colors.
       for (int i = 0; i < gvMyLista.Rows.Count; i++)
       {
           // get your data as...
          // gvMyLista.Rows[i].Cells[2].Text
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a gridview control which will show X amount of rows. I want to
I have a asp:GridView which contains a asp:TextBox within a TemplateField. I would like
Hello I have a gridView which I use to show some pictures on (small
I have a GridView control on an ASP page, which I've bound to a
I have user control on a ASP.NET web page, which contains a GridView and
I have an ASP.NET GridView which displays a list of neighborhoods. I wish a
I have a GridView which is programatically filled from the DB (not a SqlDataSource
I have a GridView which I am populating by calling a method to return
I have a GridView which is databound to an XML Datasource. For one of
I have a gridview for which JQuery drag and drop method is used to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.