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

  • Home
  • SEARCH
  • 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 7185047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:19:41+00:00 2026-05-28T18:19:41+00:00

I have a gridview with some data bound to it. I also have different

  • 0

I have a gridview with some data bound to it. I also have different background for alternating rows, so the table is more readable… How do I change the color of the row background when checkbox in the first column is checked and change it back to original when it is unchecked. The problem I’m having is, how to know if original background (after unchecking the checkbox) is for normal row or for alternating row?

I know how to change row attributes like this:

protected void gvUser_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.DataRow)
    {
        e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#D9ECFB'");
        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle;");
    }
}

But, what if there are more checkboxes selected, how do I know which is the original background?

  • 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-05-28T18:19:42+00:00Added an answer on May 28, 2026 at 6:19 pm

    I will give a jQuery solution and I hope you like it. What I do here is to find all the checkbox that are inside the GridView control, and then when you click on one of them I get the full line and change the color, but keeping the old one to bring it back. Only one note, you must place on the rows the style .row

    function InitTheChecks()
    {
        var updateButtons = jQuery('#<%=GridView.ClientID%> input[type=checkbox]');
    
        updateButtons.each(function (){
            jQuery(this).attr('onclick', null).click(function () 
            {
                var ThisCheckBox = jQuery(this);
    
                if(ThisCheckBox.is(':checked'))
                {
                    ThisCheckBox.attr('oldBackColor', ThisCheckBox.parents(".row").css("background-color"));
                    ThisCheckBox.parents(".row").css("background-color", "#FFD8CE");
                }
                else
                {
                    ThisCheckBox.parents(".row").css("background-color", ThisCheckBox.attr('oldBackColor'));
                }
            });
        });    
    }    
    

    and run the InitTheChecks() OnPage load.

    how to know if original background 
    

    To answer to this question, what I do is that I place the old color in an attribute on the tag before I change it, something like a memory keeper 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have bound fields in GridView to some dateTime property of data objects. The
Background: I have a ListView / GridView with several columns. In some situations, only
I'm instantiating an asp:Button inside a data-bound asp:GridView through template fields. Some of the
I am working on an ASP.Net website and have a GridView displaying some data,in
I have a MVC application with Jquery; I have a gridview with some data
I have a GridView and when some data has been inserted I have called
I have a GridView and I need update some data inserting HTML CODE; I
I have a GridView which is showing some data: Entity_ID (PK) Name Description Now
I have a gridview with some data and two hyperlinkfields I want to make
I have a Gridview within an UpdatePanel that shows some data from my Database.

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.