Hi all
I have datagridview that shows tasks to be done by user.One of gridview column shows priority of task as icon.Now i want to add tooltiptext to icon as "high priority, low priority or medium".

Dani AI

Generated

This thread shows a common ambiguity: "datagridview" can mean an ASP.NET GridView (WebForms) or a WinForms DataGridView. 's inline ItemTemplate is a quick declarative fix for WebForms and is fine for small pages; below are alternative options that improve maintainability, accessibility, and localization.

For ASP.NET GridView, set the image tooltip in the RowDataBound event so the logic lives in one place and strings can come from resources:

Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim drv = CType(e.Row.DataItem, DataRowView)
        Dim img = CType(e.Row.FindControl("imgPriority"), Image)
        If img IsNot Nothing Then
            Dim p = drv("Priority").ToString().ToLowerInvariant()
            Select Case p
                Case "high"
                    img.ToolTip = "High priority"
                Case "medium"
                    img.ToolTip = "Medium priority"
                Case Else
                    img.ToolTip = "Low priority"
            End Select
            img.AlternateText = img.ToolTip
        End If
    End If
End Sub

For WinForms DataGridView, use the CellToolTipTextNeeded event (and ensure ShowCellToolTips = True) so tooltips update on demand without editing every cell:

Private Sub DataGridView1_CellToolTipTextNeeded(sender As Object, e As DataGridViewCellToolTipTextNeededEventArgs) Handles DataGridView1.CellToolTipTextNeeded
    If e.RowIndex >= 0 AndAlso e.ColumnIndex = priorityColIndex Then
        Dim v = Convert.ToString(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)
        e.ToolTipText = If(v = "High", "High priority", If(v = "Medium", "Medium priority", "Low priority"))
    End If
End Sub

Notes and troubleshooting: prefer server-side code for centralized logic and easier localization (resource files). Always set image alt/AlternateText for screen readers; do not rely solely on tooltips to convey critical info. If tooltips fail to appear in WebForms, confirm the control is runat="server", the ID matches FindControl, CSS or JavaScript is not blocking pointer events, and UpdatePanel partial postbacks reapply any client-side tooltip initialization. Thanks to for the inline suggestion and to for confirming the original problem was resolved.

Recommended Answers

All 2 Replies

Hi,

try using this

<ItemTemplate>
                        <asp:Image 
                        ToolTip='<%# (DataBinder.Eval(Container.DataItem, "Title").ToString().ToLower() == "mr")? "High priority" : ((DataBinder.Eval(Container.DataItem, "Title").ToString().ToLower() == "ms")?"Medium priority":"Low priority" ) %>' 
                        runat="server" AlternateText="" ID="imgPriority" 
                        ImageUrl='<%# (DataBinder.Eval(Container.DataItem, "Title").ToString().ToLower() == "mr")? "/Testweb/images/Mr.gif" : ((DataBinder.Eval(Container.DataItem, "Title").ToString().ToLower() == "ms")?"/Testweb/images/Ms.gif":"/Testweb/images/Mrs.gif" ) %>' />
                        </ItemTemplate>

Hi
My problem is solved::idea i got from yours code.
Thank yo;u p.k chaudhry

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.