如何为RadGrid行设置RadToolTip?

时间:2013-03-25 09:36:23

标签: asp.net telerik tooltip radgrid

如何为RadGrid行设置RadToolTip?

<asp:Label ID="lblCustomerName" runat="server" Text='<%# Eval("CustomerName") %>'>
</asp:Label>
<telerik:RadToolTip ID="RadToolTip3" runat="server" TargetControlID="lblCustomerName" 
    Width="400px" RelativeTo="Element" Position="BottomCenter"  AutoCloseDelay="50000">
             this is some content
</telerik:RadToolTip>

3 个答案:

答案 0 :(得分:2)

挂钩ItemCreated事件,该事件为RadGrid中的每一行触发。然后你可以看到该行的工具提示。

protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem gridItem = e.Item as GridDataItem;
        foreach (GridColumn column in RadGrid1.MasterTableView.RenderColumns)
        {
            if (column is GridBoundColumn)
            {
                //this line will show a tooltip based on the CustomerID data field
                gridItem[column.UniqueName].ToolTip = "CustomerID: " + 
                    gridItem.OwnerTableView.DataKeyValues[gridItem.ItemIndex]["CustomerID"].ToString();

                //This is in case you wish to display the column name instead of data field.
                //gridItem[column.UniqueName].ToolTip = "Tooltip: " + column.UniqueName;
            }
        }
    }
}

http://www.telerik.com/help/aspnet-ajax/grid-appearance-tooltips-for-grid-items.html

答案 1 :(得分:0)

protected void rgCareActivity_ItemDataBound(object source, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;

        Control target = e.Item.FindControl("lblCustomerName");
        if (!Object.Equals(target, null))
        {
            if (!Object.Equals(this.RadToolTip3, null))
            {
                //Add the button (target) id to the tooltip 
                this.RadToolTip3.TargetControls.Add(target.ClientID, (e.Item as GridDataItem).GetDataKeyValue("ID").ToString(), true);
            }
        }
    }
}

protected void RadToolTip3_AjaxUpdate(object sender, ToolTipUpdateEventArgs e)
{    
    string strValue = e.Value;
    RadToolTip3.Text = strValue ;
}

答案 2 :(得分:0)

你可以试试这个。

protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem gridItem = e.Item as GridDataItem;
        Control lblItem = gridItem.FindControl("lblCustomerName");
        Control toolTipItem = gridItem.FindControl("RadToolTip3");
        if (!Object.Equals(lblItem , null) && !Object.Equals(toolTipItem , null))
        {
            ((RadToolTip)toolTipItem).TargetControlID = lblItem.ID;
        }
    }
}