Thursday 8 July, 2010

GRIDVIEW MOUSEOVER COLOR

  1. protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
  2. {
  3. DataControlRowType rtype = e.Row.RowType;
  4. if (rtype == DataControlRowType.DataRow && rtype != DataControlRowType.Footer && rtype != DataControlRowType.Separator && rtype != DataControlRowType.Header && rtype != DataControlRowType.Pager)
  5. {
  6. e.Row.Attributes.Add("onmouseover", "Highlight(this,'#DCEDFF');");
  7. e.Row.Attributes.Add("onmouseout", "resetColorRows('#ffffff','#eeeeee');");
  8. }
  9. }
  10. <script type="text/javascript">
  11. function Highlight(row,color)
  12. {
  13. row.style.backgroundColor=color;
  14. }
  15. function resetColorRows(color1,color2)
  16. {
  17. var bgColor;
  18. t = document.getElementsByTagName("tr");
  19. for (var i=1; i<t.length; i++)
  20. {
  21. if ((i % 2) == 1)
  22. bgColor = color1;
  23. else
  24. bgColor = color2;
  25. t[i].style.backgroundColor = bgColor;
  26. }
  27. }
  28. script>

No comments:

Post a Comment