Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you put a tooltip on datagrid column

Status
Not open for further replies.

LauraCairns

Programmer
Jul 26, 2004
173
GB
Is it possible to add a tooltip in the column of a Datagrid. Can someone please show me how I would do this for the datagrid column below. Thanks for any help anyone can give me.

Here is the datagrid coloum which I want to put the tooltip
when the user hovers over it.

<asp:BoundColumn DataField="ID" SortExpression="ID" HeaderText="ID">
<HeaderStyle ForeColor="White" CssClass="dgHeader">
</HeaderStyle>
<ItemStyle Font-Size="10pt" Height="11px" CssClass="A">
</ItemStyle>
</asp:BoundColumn>
 
Laura: one solution:

Code:
Sub dgSites_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.DataGridItemEventArgs)
      If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then 
         'Add the OnMouseOver and OnMouseOut method to the Row of DataGrid
         e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#CCFFFF'")
         e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=''") 
         e.Item.Cells(0).Style("cursor") = "hand" 
         e.item.cells(0).Tooltip = "Hello"
      End If                     
End Sub

 
Thats brilliant but never used vb before and was wondering if you knew how to write this in c#

Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated

If e.Item.ItemType = ListItemType.Header Then
e.item.cells(0).Tooltip = "Name"
e.item.cells(1).Tooltip = "Age"

end if

End Sub
 
Laura: I don't code in C# but see if this will get you close enough

Code:
private void dgResults_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
    foreach (DataGridItem dgItem in dgResults.Items)
    {
      if (e.Item.ItemType == ListItemType.Header)
        e.item.cells(0).Tooltip = "Name";
            e.item.cells(1).Tooltip = "Age";
  }
}

Laura, do a "Search" using the term "DataGridItemEvent" and there should be several pages of results, and also several examples of C# using the ItemBound event.
 
thanks this is brilliant got it working perfectly. Now on to trying to add a tooltip to the button on a databound column, if I can do it easily
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top