title: How to change the gridview row colors in onclick event in javascript?
body: <p>I wrote the following <code>GridView</code> code in ASP.NET. I set the <code>AlternatingRow</code> style's <code>BackColor</code> to bisque. The remaining rows are set to white.</p>
  
  <p>This code exists within my <code>grdRequests_RowDataBound</code> event:</p>
  
  <pre><code>if (e.Row.RowType == DataControlRowType.DataRow)
  {
      e.Row.Attributes.Add("onclick", "ChangeRowColor(this)");
      e.Row.Attributes.Add("onmouseover", "this.style.cursor=\'pointer\'");
  }
  </code></pre>
  
  <p>The JavaScript <code>ChangeRowColor</code> code above is as follows:</p>
  
  <pre><code>function ChangeRowColor(row) 
  {
      if (previousRow == row) 
          return;         
  
      else if (previousRow != null)
          var color = row.style.backgroundColor;
  
      if (previousRow != null) {
  
          alert(color)
  
          if (color == "bisque") {
              previousRow.style.backgroundColor = "white";
          }
          else if (color == "white") {
              previousRow.style.backgroundColor = "bisque";
          }        
      }
  
      row.style.backgroundColor = "#ffffda";
      previousRow = row;    
  }
  </code></pre>
  
  <p>When I click the row, I need to change the color like yellow. After selecting another row, I need to switch the previous row's color back to its old color, but in my code this doesn't work. Any suggestions?</p>