Tips and tricks for .NET using ASP and VB code.

Display header in GridView cell when mouse pointer hovers over it

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Or (e.Row.RowType = DataControlRowType.Header) Then
For Each GridViewDataControlFieldCell As DataControlFieldCell In e.Row.Cells
'Remove any hidden hyphens that might be in the header.
Dim GridViewHeaderText As String = GridViewDataControlFieldCell.ContainingField.HeaderText.Replace(Chr(173), "")
If e.Row.RowType = DataControlRowType.DataRow Then
GridViewDataControlFieldCell.Attributes.Add("Title", GridViewHeaderText)
GridViewDataControlFieldCell.Attributes.Add("onmouseover", "this.bgColor='lightyellow'")
GridViewDataControlFieldCell.Attributes.Add("onmouseout", "this.bgColor=''")
Else
GridViewDataControlFieldCell.Attributes.Add("Title", "Click link to sort by " & GridViewHeaderText)
End If
Next
End If
End Sub

No comments:

Post a Comment

Search This Blog