Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

how to add ToolTip for drop down list... which contain data from backend....


this is the code i am using


C#
private void AttachTooltipForDropdowns(DropDownList ddlTarget)
{
    for (int i = 0; i < ddlTarget.Items.Count; i++)
    {
        ddlTarget.Items[i].Attributes.Add("title", ddlTarget.Items[i].Text);
    }
}
<br />
protected void Page_Prerender(object sender, EventArgs e)
{
    AttachTooltipForDropdowns(ddlf1);
    AttachTooltipForDropdowns(ddlf2);
}


ddlf1,ddlf2 are the ID 's of the ddl, but it is not working.

valuable suggestion and solutions... plz
Posted
Updated 31-Aug-10 1:42am
v2

You might want to try changijng your method's parameter list:

C#
private void AttachTooltipForDropdowns(ref DropDownList ddlTarget)
{
    for (int i = 0; i < ddlTarget.Items.Count; i++)    
    {
        ddlTarget.Items[i].Attributes.Add("title", ddlTarget.Items[i].Text);    
    }
}

protected void Page_Prerender(object sender, EventArgs e)
{
    AttachTooltipForDropdowns(ref ddlf1);
    AttachTooltipForDropdowns(ref ddlf2);
}
 
Share this answer
 
Comments
sarala.s 31-Aug-10 8:24am    
NO.... john...it is not working......any other suggestion???
Sandeep Mewara 31-Aug-10 14:39pm    
Just a guess/question that comes to my mind: By any chance are you looking this in IE6?
If so, you may not be able to see the ToolTip text of dropdownlist items in IE 6.0. i
It works with higher version of IE.
Try to call the method "AttachTooltipForDropdowns" in pre_render event of dropdownlist. It worked for me.


C#
protected void Page_InitComplete(object sender, EventArgs e)
{
drp.PreRender += new EventHandler(DropDown_PreRender);
}

 public void DropDown_PreRender(object sender, EventArgs e)
        {
            DropDownList ddl = sender as DropDownList;
            if (ddl != null)
            {
                foreach (ListItem li in ddl.Items)
                {
                    // setting text value of item as tooltip
                    li.Attributes.Add("title", li.Text);
                }
            }
        }
  {
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900