Tooltip on GridHyperLinkColumn

4 posts, 1 answers
  1. Daniel
    Daniel avatar
    175 posts
    Member since:
    Feb 2009

    Posted 21 Sep 2009 Link to this post

    Hi. I'm using RadControls for ASP.NET AJAX 2009_2_826_dev. I'm trying to set the tooltip on all columns to be the same. Everything works except the GridHyperLinkColumn(s). I can set the 'text' property okay, so I know my code behind is trying to set it on the correct grid item. Thanks in advance.

    Daniel

        protected void rgPeople_ItemCreated(object sender, GridItemEventArgs e)  
        {  
            if (e.Item is GridDataItem)  
            {  
                GridDataItem gridItem = e.Item as GridDataItem;  
                foreach (GridColumn column in rgPeople.MasterTableView.RenderColumns)  
                {  
                    if (column is GridBoundColumn)  
                    {  
                        gridItem[column.UniqueName].ToolTip = gridItem.OwnerTableView.DataKeyValues[gridItem.ItemIndex]["pkEmployeeNumber"].ToString();  
                    }  
                }  
            }  
        }  
     

                            <telerik:RadGrid ID="rgPeople" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" 
                                GridLines="None" Skin="Simple" OnPreRender="rgPeople_PreRender" DataSourceID="sdsPeople" EnableLinqExpressions="False" 
                                runat="server" OnItemCreated="rgPeople_ItemCreated">  
                                <MasterTableView AutoGenerateColumns="False" DataKeyNames="pkEmployeeNumber">  
                                    <RowIndicatorColumn> 
                                        <HeaderStyle Width="20px" /> 
                                    </RowIndicatorColumn> 
                                    <ExpandCollapseColumn> 
                                        <HeaderStyle Width="20px" /> 
                                    </ExpandCollapseColumn> 
                                    <Columns> 
                                        <telerik:GridHyperLinkColumn DataNavigateUrlFields="pkEmployeeNumber" SortExpression="firstName" 
                                            UniqueName="firstName" DataNavigateUrlFormatString="/people/profiles/?empno={0}" 
                                            HeaderText="First Name" DataTextField="firstName" DataType="System.String">  
                                        </telerik:GridHyperLinkColumn> 
                                        <telerik:GridBoundColumn DataField="firstName" HeaderText="First Name" SortExpression="firstName" 
                                            UniqueName="firstNameSort" Display="false" DataType="System.String">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="lastName" HeaderText="Last Name" SortExpression="lastName" 
                                            UniqueName="lastName">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="positionDescription" HeaderText="Title" SortExpression="positionDescription" 
                                            UniqueName="positionDescription">  
                                        </telerik:GridBoundColumn> 
                                        <intra:FilteringColumnPeople DataField="directorate" FilterControlWidth="180px" HeaderText="Directorate">  
                                            <headerstyle width="15%" /> 
                                            <itemtemplate> 
                                                <%# Eval("directorate")%> 
                                            </itemtemplate> 
                                        </intra:FilteringColumnPeople> 
                                        <telerik:GridBoundColumn DataField="phone" HeaderText="Phone" SortExpression="phone" 
                                            UniqueName="phone">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="email" HeaderText="Email" SortExpression="email" 
                                            UniqueName="email">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="pkEmployeeNumber" HeaderText="pkEmployeeNumber" SortExpression="pkEmployeeNumber" 
                                            UniqueName="pkEmployeeNumber" Display="false">  
                                        </telerik:GridBoundColumn> 
                                    </Columns> 
                                </MasterTableView> 
                            </telerik:RadGrid> 
     



  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Sep 2009 Link to this post

    Hello Daniel,

    You can try out the following code to set the tooltip for the hyperlink column in the grid. You would also have to use the ItemDataBound event of the grid instead of the ItemCreated event inorder to implement this.
    c#:
     protected void rgPeople_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                GridDataItem gridItem = e.Item as GridDataItem; 
                foreach (GridColumn column in rgPeople.MasterTableView.RenderColumns) 
                { 
                    if (column is GridBoundColumn) 
                    { 
                        gridItem[column.UniqueName].ToolTip = gridItem.OwnerTableView.DataKeyValues[gridItem.ItemIndex]["pkEmployeeNumber"].ToString(); 
                    } 
                    if (column is GridHyperLinkColumn) 
                    {                    
                        (gridItem[column.UniqueName].Controls[0] as HyperLink).ToolTip = gridItem.OwnerTableView.DataKeyValues[gridItem.ItemIndex]["pkEmployeeNumber"].ToString(); 
                    } 
                } 
            }  
         }   

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Daniel
    Daniel avatar
    175 posts
    Member since:
    Feb 2009

    Posted 21 Sep 2009 Link to this post

    Thanks Princy that worked a treat!

    Daniel
  5. Martin
    Martin avatar
    84 posts
    Member since:
    Apr 2009

    Posted 13 Jul Link to this post

    Actually you can do it much simpler

                    GridTableCell gtcMyCell = (GridTableCell)item["Your_Unique_Name"];
                    gtcMyCell.ToolTip = "Your Tool Tip"; //set tooltip of the cell
                    (gtcMyCell.Controls[0] as HyperLink).ToolTip = "Your_Unique_Name"; //set tootip of link itself

Back to Top