Refactor Code

  • Gravatar
    Changing GridView Row Color on OnMouseOver Event

    by azamsharp on 5/12/2008 2:30:37 PM
  • Here is some code that is used to change the row color of the GridView control when the mouse is placed over the row.
  • protected void MyGridView_RowCreated(object sender, GridViewRowEventArgs e)
    {

    string onmouseoverStyle = "this.style.backgroundColor='blue'";

    string onmouseoutStyle = "this.style.backgroundColor='@BackColor'";

    string rowBackColor = String.Empty;

    if (e.Row.RowType == DataControlRowType.DataRow)

    {

    if (e.Row.RowState == DataControlRowState.Alternate)

    rowBackColor = System.Drawing.ColorTranslator.ToHtml(MyGridView.AlternatingRowStyle.BackColor).ToString();

    else rowBackColor = System.Drawing.ColorTranslator.ToHtml(MyGridView.RowStyle.BackColor).ToString();

    e.Row.Attributes.Add("onmouseover", onmouseoverStyle);

    e.Row.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor",rowBackColor));

    }

    }
  • Refactor it!
  • Gravatar
    Intenté obtener el resultado a través de tú código, no tuve mucha suerte, pues no me funcionó. Luego buscando en codeproject.com me encontré con una simulación similar a lo de hotmail. He aqui la dirección: http://www.codeproject.com/KB/webforms/HotmailGridView.aspx
    by Alin on 6/5/2008 9:51:45 AM
  • protected void gvHotmail_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate))
    {
    HtmlInputCheckBox chkBxMail = (HtmlInputCheckBox)e.Row.Cells[1].FindControl("chkBxMail");
    Image imgMail = (Image)e.Row.Cells[1].FindControl("imgMail");

    e.Row.Attributes["onmouseover"] = string.Format("javascript:ItemMouseOver(this,'{0}','{1}');", chkBxMail.ClientID, imgMail.ClientID);
    e.Row.Attributes["onmouseout"] = string.Format("javascript:ItemMouseOut(this,'{0}','{1}');", chkBxMail.ClientID, imgMail.ClientID);
    chkBxMail.Attributes["style"] = "display:none;";
    }
    }
Please log in to refactor the code! Login