We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

rengber on 02/03/08


Tagged

aspnet DataGrid ADONet


Versions (?)


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.