Display large text field column in tooltip

5 posts, 0 answers
  1. johnathan
    johnathan avatar
    11 posts
    Member since:
    Apr 2008

    Posted 13 Jan 2009 Link to this post

    are there any examples of how to display a large text field in a tooltip. I have a column on my grid that is truncated and on mouse over I would like the tooltip to display the text. The column is a htmleditcolumn which has no ID field, just a unique name field. i looked through the samples, but they provide much more elaborate scenarios than I have, thanks
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 13 Jan 2009 Link to this post

    Hello Jonathan,

    You can try out the following code to display a tooltip on hovering over the cells in a particular column.
    aspx:
    <telerik:RadGrid ID="RadGrid1" runat="server" Width="1000"  DataSourceID="SqlDataSource1" OnItemDataBound="RadGrid1_ItemDataBound" >            
         <MasterTableView DataKeyNames="ContactName" DataSourceID="SqlDataSource1" > 
                   

    cs:
     protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
     
            if (e.Item is GridDataItem) 
            { 
               GridDataItem dataItem = (GridDataItem)e.Item; 
               string strtxt = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ContactName"].ToString();  
               dataItem["ContactName"].ToolTip = strtxt
            }   
        } 
     

    Thanks
    Princy.
  3. Dimo
    Admin
    Dimo avatar
    8456 posts

    Posted 13 Jan 2009 Link to this post

    Hello Jonathan,

    Unfortunately, the size of system browser tooltips cannot be controlled, so if you want to display more text, please consider using RadToolTip / RadToolTipManager.


    Best wishes,
    Dimo
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  4. johnathan
    johnathan avatar
    11 posts
    Member since:
    Apr 2008

    Posted 13 Jan 2009 Link to this post

    My apologizes, I am using the radtooltip control.  Will I still be able to use the code from princey using the radtooltip?
  5. Dimo
    Admin
    Dimo avatar
    8456 posts

    Posted 13 Jan 2009 Link to this post

    Hello Johnathan,

    Yes, Princy's code will still be of use.

    If you are using RadToolTip, then you should implement something like this. Note that the RadToolTips resize automatically to accommodate their content, but you can also set Width and Height to RadToolTipManager.


    <%@ Page Language="C#" %> 
    <%@ Import Namespace="System.Data" %> 
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
     
    <script runat="server"
     
        protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                RadGrid grid = sender as RadGrid; 
                GridDataItem item = e.Item as GridDataItem; 
                foreach (GridColumn col in grid.MasterTableView.RenderColumns) 
                { 
                    if (col is GridBoundColumn) 
                    { 
                        (item[col.UniqueName] as TableCell).ToolTip = item[col.UniqueName].Text; 
                    } 
                } 
            } 
        } 
         
        protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) 
        { 
            DataTable dt = new DataTable(); 
            DataRow dr; 
            int colsNum = 5
            int rowsNum = 100
            string colName = "Column"
     
            for (int j = 1; j <= colsNum; j++) 
            { 
                dt.Columns.Add(String.Format("{0}{1}", colName, j)); 
            } 
     
            for (int i = 1; i <= rowsNum; i++) 
            { 
                dr = dt.NewRow(); 
     
                for (int k = 1; k <= colsNum; k++) 
                { 
                    dr[String.Format("{0}{1}", colName, k)] = String.Format("{0}{1}Row{2}{0}{1}Row{2}{0}{1}Row{2}", colName, k, i); 
                } 
                dt.Rows.Add(dr); 
            } 
     
            (sender as RadGrid).DataSource = dt
        } 
     
    </script> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <html xmlns="http://www.w3.org/1999/xhtml"
    <head runat="server"
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <title>RadControls for ASP.NET AJAX</title> 
    <style type="text/css"
     
    /*Firefox fix*/ 
     
    .GridRow_Default td, 
    .GridAltRow_Default td 
        overflow:hidden; 
     
    </style> 
    </head> 
    <body> 
    <form id="form1" runat="server"
    <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
     
    <telerik:RadToolTipManager ID="RadToolTipManager1" runat="server" AutoTooltipify="true" /> 
     
    <p>Hover a RadGrid cell in order to view a RadToolTip:</p> 
     
    <telerik:RadGrid 
        ID="RadGrid1" 
        runat="server" 
        Width="600px" 
        AllowPaging="true" 
        PageSize="20" 
        OnNeedDataSource="RadGrid_NeedDataSource" 
        OnItemDataBound="RadGrid_ItemDataBound"
        <MasterTableView TableLayout="Fixed" /> 
        <ClientSettings> 
            <Scrolling AllowScroll="true" UseStaticHeaders="true" /> 
        </ClientSettings> 
    </telerik:RadGrid> 
     
    </form> 
    </body> 
    </html> 
     



    Greetings,
    Dimo
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top