There are many cases when you want you grid to show a tooltip when an item is hovered with the mouse. Tooltips are understood by screen readers and can be used as an accessibility feature.
In brief you need to handle either ItemDataBound or ItemCreated Event. Usually, the tooltips are displayed for the header and the grid data cells
In the first case you show the tooltips only when GridHeaderItem is hovered. In this case you should check in the event handler if e.Item is GridHeaderItem.
The second scenario is when the tooltips will be shown for any grid item. In this case you should check if e.Item is GridDataItem.
protectedvoidRadGrid1_NeedDataSource(object sender,GridNeedDataSourceEventArgs e){
RadGrid1.DataSource = Enumerable.Range(1,60).Select(x =>new{
ID = x,
Name ="Name "+ x,
Description ="Description for "+ x
});}protectedvoidRadGrid1_ItemDataBound(object sender,GridItemEventArgs e){//Check for GridHeaderItem if you want tooltips for the header cellsif(e.Item isGridHeaderItem){GridHeaderItem headerItem = e.Item asGridHeaderItem;foreach(GridColumn column in RadGrid1.MasterTableView.RenderColumns){
headerItem[column.UniqueName].ToolTip = column.UniqueName;}}if(e.Item isGridDataItem){GridDataItem gridItem = e.Item asGridDataItem;foreach(GridColumn column in RadGrid1.MasterTableView.RenderColumns){//this line will show a tooltip based on the ID data field
gridItem[column.UniqueName].ToolTip ="ID: "+
gridItem.GetDataKeyValue("ID").ToString();//This is in case you wish to display other row valueif(column.UniqueName =="Name"){
gridItem[column.UniqueName].ToolTip = gridItem["Description"].Text;}}}}
VB
ProtectedSub RadGrid1_NeedDataSource(sender AsObject, e As GridNeedDataSourceEventArgs)
RadGrid1.DataSource = Enumerable.Range(1,60).[Select](Function(x)NewWith{
.ID = x,
.Name="Name "& x,
.Description ="Description for "& x
})EndSubProtectedSub RadGrid1_ItemDataBound(ByVal sender AsObject,ByVal e As GridItemEventArgs)IfTypeOf e.Item Is GridHeaderItem ThenDim headerItem As GridHeaderItem =TryCast(e.Item, GridHeaderItem)For Each column As GridColumn In RadGrid1.MasterTableView.RenderColumns
headerItem(column.UniqueName).ToolTip = column.UniqueName
NextEndIfIfTypeOf e.Item Is GridDataItem ThenDim gridItem As GridDataItem =TryCast(e.Item, GridDataItem)For Each column As GridColumn In RadGrid1.MasterTableView.RenderColumns
gridItem(column.UniqueName).ToolTip ="ID: "& gridItem.GetDataKeyValue("ID").ToString()If column.UniqueName ="Name"Then
gridItem(column.UniqueName).ToolTip = gridItem("Description").TextEndIfNextEndIfEndSub
You can also ad Tooltips using JavaScript. And if you want to display the unique ID of the item, you can set the field name to the ClientDataKeyNames collection. More information you can find here:
This example is also fully isolated and you can simply copy-paste it to your web site.
ASP.NET
<telerik:RadGridID="RadGrid1"runat="server"AllowPaging="True"Width="800px"OnNeedDataSource="RadGrid1_NeedDataSource"><ClientSettings><%--This can be OnDataBound if you are using client-side binding--%><ClientEventsOnGridCreated="gridCreated"/></ClientSettings><MasterTableViewDataKeyNames="ID"ClientDataKeyNames="ID"></MasterTableView></telerik:RadGrid>
C#
protectedvoidRadGrid1_NeedDataSource(object sender,GridNeedDataSourceEventArgs e){
RadGrid1.DataSource = Enumerable.Range(1,60).Select(x =>new{
ID = x,
Name ="Name "+ x,
Description ="Description for "+ x
});}
VB
ProtectedSub RadGrid1_NeedDataSource(sender AsObject, e As GridNeedDataSourceEventArgs)
RadGrid1.DataSource = Enumerable.Range(1,60).[Select](Function(x)NewWith{
.ID = x,
.Name="Name "& x,
.Description ="Description for "& x
})EndSub
Telerik UI for ASP.NET AJAX provides its own RadToolTip component which can be used to match the skin and theme of your app. In addition, it also provides rich functionality like dynamic AJAX loading depending on the targeted value and auto-tooltipify of an entire area.
You can check these implementation and use them in your own project: