add tool tip in grid with add control during itemDataBound

3 posts, 0 answers
  1. CH
    CH avatar
    28 posts
    Member since:
    Nov 2008

    Posted 23 May 2011 Link to this post

    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);
  2. Marin Bratanov
    Marin Bratanov avatar
    3907 posts

    Posted 25 May 2011 Link to this post

    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: 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,
    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.

  3. CH
    CH avatar
    28 posts
    Member since:
    Nov 2008

    Posted 26 May 2011 Link to this post

    It works.... Thks for your immediately response.!
Back to Top