Posted By

rengber on 02/03/08


Tagged

aspnet DataGrid ADONet


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


Adding Eventhandlers to DataGrid Rows


 / Published in: C#
 

  1. //Codebehind
  2. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  3. {
  4. if (e.Row.RowType == DataControlRowType.DataRow)
  5. {
  6. e.Row.Attributes.Add("onmouseover", "MouseOn(this)");
  7. e.Row.Style["cursor"] = "pointer;hand;";
  8. e.Row.Attributes.Add("onmouseout", "MouseOff(this)");
  9. e.Row.Attributes.Add("onclick", "window.location=\'ViewDetailRecord.aspx?ItemId=" + e.Row.Cells[0].Text + "\'");
  10. }
  11. }
  12.  
  13. //Page HTML
  14. <script type="text/javascript" language="javascript">
  15. var holding = "white";
  16. function MouseOn(elem)
  17. {
  18. holding = elem.style.backgroundColor;
  19. elem.style.backgroundColor = "#f2f2f2";
  20. //alert(elem.style.backgroundColor);
  21. }
  22. function MouseOff(elem)
  23. {
  24. //alert(holding);
  25. elem.style.backgroundColor = holding;
  26. }
  27. </script>

Report this snippet  

You need to login to post a comment.