Other Recent Articles

Javascript to color Gridview cells based on value

By Eranda Ketawalage on Thursday, September 8, 2011 0 comments

Think that you have to apply a color for a cell and the cell values are "Yes" or "No"



  1. put the following Javascript and the Style withing the head tags



    <style type="text/css">

    .PendingRowStyle
    {
        padding: 2px;
        border: solid 1px #c1c1c1;
        color: Black;
        background-color:#ffcccc;
    }

    </style>




<script language="javascript" type="text/javascript">
   function ColourCell() {
     var Grid = document.getElementById("<%=GridView1.ClientID %>");
     if (Grid != null) {
      for (i = 0; i < Grid .rows.length; i++) {
       var cell = Grid .rows[i].cells;
       if (cell != null)
        if (cell.length == 5) {  
// 5 - Number of columns of your grid
         if (cell[4].firstChild.data.trim() == "Yes") {  
// 4 - cell you want to check 
          gvDrv.rows[i].all[4].className = " PendingRowStyle";    
//4 - cell you want to color
         }
        }
       }
      }
   }
</script>

   2.  Put the Following tags within body tag


    <script type="text/javascript">
        window.onload = ColourCell;
    </script>

Category:

0 comments:

Post a Comment

Amazon

Share this