Adding Eventhandlers to DataGrid Rows


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.