Search code examples
asp.netvb.nettooltipboundcolumn

ASP.NET BoundColumn ToolTip


Is there a way to add a tool tip to a BoundColumn? This is my code....

    <asp:BoundColumn DataField="PersonName" SortExpression="PersonName" HeaderText="Name">
        <HeaderStyle HorizontalAlign="Center" Width="10%" VerticalAlign="Top"></HeaderStyle>
        <ItemStyle HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
    </asp:BoundColumn>

I was using a tablecell before and decided to switch to a bound column, in doing so I realized tooltips are not an attribute of boundcolumn, I need tooltips.


Solution

  • So it's actually a DataGrid control and you want to have a tooltip on the header-cell. You can use ItemDataBound:

    Protected Sub SortableDataGrid_ItemDataBound(sender As Object, e As DataGridItemEventArgs) Handles Grid0.RowDataBound
        Select Case e.Item.ItemType
            Case ListItemType.Header
                'presuming it's the first column:
                e.Item.Cells(0).ToolTip = "Your tooltip for this header cell"
        End Select
    End Sub
    

    If it's a GridView the code is similar:

    Protected Sub SortableGridView_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles Grid0.RowDataBound
        Select Case e.Row.RowType
            Case DataControlRowType.Header
                'presuming it's the first column:
                e.Row.Cells(0).ToolTip = "Your tooltip for this header cell"
        End Select
    End Sub