Show Tooltip in DropDown list items

In design Page :

<asp:DropDownList ID="DropDownList1" runat="server" ondatabound="DropDownList1_DataBound">
</asp:DropDownList>

In CS page :

protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dTable = new DataTable("Dynamically_Generated");
        DataColumn name = new DataColumn("Name", typeof(string));
        dTable.Columns.Add(name);
        dTable.Rows.Add("sanjeet");
        dTable.Rows.Add("ajay");
        dTable.Rows.Add("sonu");
        dTable.Rows.Add("dipu");
        DropDownList1.DataSource = dTable;
        DropDownList1.DataTextField = "Name";
        DropDownList1.DataValueField = "Name";
        DropDownList1.DataBind();
    }
    protected void  DropDownList1_DataBound(object sender, EventArgs e)
    {
        DropDownList ddl = sender as DropDownList;
        if (ddl != null)
        {
            foreach (ListItem li in ddl.Items)
            {
                li.Attributes["title"] = li.Text;
            }
        }
    }

Comments