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

Set item tooltips in RadDropDownList

1 Answer 232 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Bruce
Top achievements
Rank 1
Bruce asked on 05 Jun 2013, 10:05 PM
I have a RadDropDownList that I bind to a List of State objects. The DataTextField is set to the state abbreviation property, and the DataValueField is set to a Guid identifier. I want to set the tooltip of the list items to the state name, IE. AK = Alaska. I have tried a few different ways to do this, but none are working. In each case I have stepped through the code to verify that each item gets the proper value assigned to it. In the browser though there are no tool tips.

Method 1: After calling DataBind() I iterate through each item in the RadDropDownList and assign the state name to the item's ToolTip property.
List<State> stateList = GetStates();
uxState.DataSource = stateList;
uxState.DataBind();
 
foreach (DropDownListItem item in uxState.Items)
{
    State state = stateList.Find(delegate(State myState)
    {
        return myState.StateId == new Guid(item.Value);
    });
    if (state != null)
    {
        item.ToolTip = state.Name;
    }
}


Method 2: Is the same as method 1 except I do all the work inside the DataBound event.

Method 3: Thinking the issue was something to do with the data binding I iterate the state object list and create new a DropDownListItem for each object. I then assign the tooltip to the new DropDownListItem and add it to the RadDropDownList.Items collection.
foreach (State state in List<State>)
{
    DropDownListItem item = new DropDownListItem(state.Abbreviation, state.StateId.ToString());
    item.ToolTip = state.Name;
    uxState.Items.Add(item);
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 06 Jun 2013, 07:33 AM
Hi Bruce,

Try the following code snippet to set tooltips in RadDropdownList items.
ASPX:
<telerik:RadDropDownList ID="RadDropDownList1" runat="server" DataTextField="factor">
 <ItemTemplate>
  <asp:Label runat="server" ID="Label1" Text='<%# Eval("factor")%> '></asp:Label>
  <telerik:RadToolTip ID="RadToolTip1" runat="server" Width="100" Height="10" TargetControlID="Label1" Position="BottomRight" Text='<%# Eval("factor")%>'>
  </telerik:RadToolTip>
 </ItemTemplate>
</telerik:RadDropDownList>
Note: Databinding in code behind

Thanks,
Shinu.
Tags
DropDownList
Asked by
Bruce
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or