Return to Snippet

Revision: 5001
at February 3, 2008 19:46 by rengber


Updated Code
//Codebehind  
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {            
            e.Row.Attributes.Add("onmouseover", "MouseOn(this)");
            e.Row.Style["cursor"] = "pointer;hand;";
            e.Row.Attributes.Add("onmouseout", "MouseOff(this)");
            e.Row.Attributes.Add("onclick", "window.location=\'ViewDetailRecord.aspx?ItemId=" + e.Row.Cells[0].Text + "\'");
        }
    }

//Page HTML
    <script type="text/javascript" language="javascript">
      var holding = "white"; 
      function MouseOn(elem)
      {
        holding = elem.style.backgroundColor; 
        elem.style.backgroundColor = "#f2f2f2"; 
        //alert(elem.style.backgroundColor);
      }
      function MouseOff(elem)
      {
        //alert(holding); 
        elem.style.backgroundColor = holding;           
      }
    </script>

Revision: 5000
at February 3, 2008 19:17 by rengber


Initial Code
protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=\'#F2F2F2\'");
            e.Row.Style["cursor"] = "pointer;hand;";
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=\'White\'");
            e.Row.Attributes.Add("onclick", "window.location=\'ViewDetailRecord.aspx?DetailId=" + e.Row.Cells[0].Text + "\'");            
        }
    }

Initial URL


Initial Description


Initial Title
Adding Eventhandlers to DataGrid Rows

Initial Tags
aspnet

Initial Language
C#