This is a migrated thread and some comments may be shown as answers.

Add tooltip to page numbers in Pager

3 Answers 146 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nitin
Top achievements
Rank 1
Nitin asked on 05 Sep 2013, 10:41 AM
In our current setup we are trying to provide accessibility to the grid for blind users. Whatever is on the screen, when the mouse is moved to the controls on the screen, the tool tip or the alt text is read out to the user. Although the tooltip for buttons in the pager are available and can be customized , there is no tooltip option for the page numbers. Because of this when we hover over the page number something like this is always shown in the status bar. javascript:__dopostback('... control value'). I would like to replace the status message on the page number links with meaningful Text that can be displayed in status bar or using a tool tip from code behind. Let me know if this is possible.

3 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 10 Sep 2013, 11:12 AM
Hi Nitin,

You can handle the ItemCreated event of RadGrid if the item is GridPagerItem, then use the Controls collection to access this buttons and set a title attribute for them.
See this help topic for general accessing of the items in RadGrid:
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

Regards,
Vasil
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Nitin
Top achievements
Rank 1
answered on 11 Sep 2013, 09:32 AM
Thanks for your reply, as per your solution, i followed the link, but it does not provide any information as to how to access the pager elements like when the pagerstyle mode is "NextPrevAndNumeric". Lets say for e.g. [1] or [2], how do I reach any of the link buttons using the GridPagerItem collection. I tried using the controls then Item with index but it goes many hierarchies down and I could not find the linkbuttons. So how to access the page numbers controls [1] [2] [3] from code behind an update their tooltip. I was trying this way using cast.
DirectCast(e.Item.Cells(0).Controls.Item(0).Controls.Item(0).Controls.Item(0),System.Web.UI.WebControls.TableCell).Controls.Item(0).Controls.Item(0)

the code behind is as follows.

Protected Sub radGrid_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles radGrid.ItemCreated
        If TypeOf e.Item Is Telerik.Web.UI.GridPagerItem Then
            If e.Item IsNot Nothing AndAlso e.Item.HasControls Then
                Dim pagerItem As GridPagerItem = TryCast(e.Item, GridPagerItem)

                For Each iItem As TableCell In pagerItem.Controls

                Next

                'CType(e.Item, Telerik.Web.UI.GridPagerItem).Cells.Item(0)
                'Dim lnkButton As LinkButton = TryCast(pagerItem.FindControl("LinkButton1"), LinkButton)
            End If

        End If
    End Sub
0
Vasil
Telerik team
answered on 16 Sep 2013, 07:23 AM
Hi Nitin,

Here is an example how to set ToolTips for the LinkButtons of the pager:
<telerik:RadGrid runat="server" OnItemCreated="RadGrid1_ItemCreated" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" AllowPaging="true" PageSize="3" PagerStyle-AlwaysVisible="true" PagerStyle-Mode="NextPrevAndNumeric">
</telerik:RadGrid>
C#
public static IEnumerable GetControls(Control control)
{
    foreach (Control c in control.Controls)
    {
        yield return c;
        if (c.Controls.Count > 0)
        {
            foreach (Control child in GetControls(c))
            {
                yield return child;
            }
        }
    }
}
 
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    GridPagerItem pager = e.Item as GridPagerItem;
    if (pager != null)
    {
        foreach (Control c in GetControls(pager))
        {
 
            LinkButton button = c as LinkButton;
            if (button != null)
            {
                button.ToolTip = button.Text;
            }
        }
    }
}

It is general code, you can actually modify the GetControls to return only the LinkButtons. Or even to set their ToolTip and to remove most of the logic in the current ItemCreated function.

Regards,
Vasil
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Nitin
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Nitin
Top achievements
Rank 1
Share this question
or