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

add tool tip in grid with add control during itemDataBound

2 Answers 132 Views
ToolTip
This is a migrated thread and some comments may be shown as answers.
CH
Top achievements
Rank 1
CH asked on 24 May 2011, 02:51 AM
Dear Sir:
 I have a telerik gird and I would like to add tool tip in grid with add control during itemDataBound. it is ok for the static control in the grid template but if i try to dynamic  add control with tool tip manager during grid itemDataBound and the tool tip didn't show up.

will you have any sample which i can follow or any correction for my coding?

Thank you very much for your support!

From Edmond
protected void grdOwnerHistory_ItemDataBound(object sender, GridItemEventArgs e)
   {
       STEPS_AdditionalOwner_DataAdapter additionalDA = new STEPS_AdditionalOwner_DataAdapter();
       STEPS_Client_DataAdapter clientDA = new STEPS_Client_DataAdapter();
        if (e.Item is GridHeaderItem)
       {
           GridHeaderItem headerItem = (GridHeaderItem)e.Item;
       }
        else if (e.Item is GridDataItem)
        {
            GridDataItem dataItem = (GridDataItem)e.Item;
            if (!Object.Equals(this.RadToolTipManager1, null))
            {
                RadToolTipManager1.TargetControls.Add(((HyperLink)dataItem["Owner_Name"].FindControl("lnkOwner_Name")).ClientID, "Owner_Name|" + dataItem["Owner_ID"].Text.Replace(" ", "").Replace("<nobr>", "").Replace("</nobr>", ""), true);
                //((HyperLink)dataItem["Owner_Name"].FindControl("lnkOwner_Name")).Font.Underline = true;
                DataSet ds = additionalDA.getAdditionalOwnerByTenureId(long.Parse(dataItem["Tenure_Id"].Text));
                foreach (DataRow dRow in ds.Tables[0].Rows){
                    DataSet clientDS = clientDA.GetClientById(CommonFunction.ConvertIDToInt64( dRow["Owner_Id"]), long.Parse(this.employeeId));
                      
                    string clientName;
                    if (clientDS.Tables[0].Rows.Count > 0){
                       clientName  = clientDS.Tables[0].Rows[0]["Rn_Descriptor"].ToString();
                         
                       HyperLink link = new HyperLink();
                       link.Text = clientName;
                       RadToolTipManager1.TargetControls.Add(link.ClientID, "Owner_Name|" + dRow["Owner_Id"].ToString(), true);
                       dataItem["Owner_Name"].Controls.Add(link);
                        
                         
                    }
                }
            }
        }
   }

2 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 25 May 2011, 03:49 PM

Hi Edmond,

I could not run the code snippet you provided because of the missing dependencies.

Nevertheless, I created a simple page where I have a static control (for comparison) and I add a control dynamically using your approach. On my end the tooltip is shown every time as you can see in the video from my experiment: http://screencast.com/t/Te9KDzb6pt. The only difference I can see between my concept and yours is that I add the control to the grid cell before trying to use its ClientID property. A control's lifecycle begins when it is added to its parent, therefore its events and properties are not created before that, which is the most likely cause for the behavior on your end - the ClientID is not yet correct when you add it to the ToolTipManager.

For your convenience I am attaching my test page so that you can use it as a reference. Please note my comments in the code.

On a side note - creating controls this late in the Grid's lifecycle is not recommended. The ItemDataBound event should be used for populating the data, while controls should be created in the ItemCreated event. If this approach is not convenient for you, though, you may still create them in the ItemDataBound event, but that may cause some issues in the future.



Kind regards,
Marin
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
CH
Top achievements
Rank 1
answered on 26 May 2011, 07:37 AM
It works.... Thks for your immediately response.!
Tags
ToolTip
Asked by
CH
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
CH
Top achievements
Rank 1
Share this question
or