locked
Disable onmouseover hover function on specific cells in gridview RRS feed

  • Question

  • User-809753952 posted

    I am using the following code to change row color onmouseover. This changes the color of the entire row. Can I disable it for a particular cell,  for example, the first cell of the row? The background color  of the first cell should remain unchanged.

      If e.Row.RowType = System.Web.UI.WebControls.DataControlRowType.DataRow Then             
                    e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#def0d8'")
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle;")
            End If

    Wednesday, February 27, 2019 9:10 AM

All replies

  • User-943250815 posted

    Easy way, instead of add events on row, add to cells

    Dim rowCells As TableCellCollection = e.Row.Cells
    For Each cell As TableCell In rowCells
      cell.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#def0d8'")
    cell.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle;") Next

    Hard way, would be make a function to check on what table cell is over

    Wednesday, February 27, 2019 2:29 PM
  • User-1716253493 posted

    Simply use the attributes in the cells instead

    If e.Row.RowType = System.Web.UI.WebControls.DataControlRowType.DataRow Then             
         e.Row.Cells(0).Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#def0d8'")
         e.Row.Cells(0).Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle;")
    End If

    If you have many cells, use iteration to set the attributes, skip the cell you want

    Thursday, February 28, 2019 6:22 AM
  • User-809753952 posted

    I want to disable onmouseover function on the first cell. But the first cell has rowspan attribute which is set code behind.

    So I cannot use  e.Row.Cells(0).Attributes.Add(....

    Tuesday, March 12, 2019 1:36 PM
  • User-943250815 posted

    What about this way. I mean check if cell has ColumnSpan Attribute

    For Each c As TableCell In e.Row.Cells
     If c.ColumnSpan > 0 Then
      c.Attributes.Remove("<attribute>")
     End If
    Next

    Wednesday, March 13, 2019 12:10 AM