Click here to Skip to main content
15,920,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I’m using a custom dropdownlist and binding elements dynamically, but here I want to show a tooltip message on every items of dropdown list.

View Code:
@Html.DropDownListFor(m => m.Industry,Model.IndustryList, "All", new { @style = "width:258px;", @class = "drpDown" })
Controller code:
IEnumerable<SelectListItem> IndustryList= EntityModel<t>.Where(m => m.t == “something”).ToList().Select(c => new SelectListItem { Text = t.Name, Value = t.Value);

So let me know is there any way to set title on every option items within select tag.
Posted

1 solution

try this may be it will help you.
remember it is only a concept to Show tooltip(or title) message on every dropdown list items,
modify it as your requirement.



aspx code

XML
<asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
            <asp:ListItem>4</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
        </asp:DropDownList>



cs code

C#
protected void Page_Load(object sender, EventArgs e)
    {
        string[] ar = new string[5];
        ar[0] = "One"; ar[1] = "Two"; ar[2] = "Three"; ar[3] = "Four"; ar[4] = "Five";
        for (int i = 0; i < DropDownList1.Items.Count - 1; i++)
        {

            DropDownList1.Items[i].Attributes.Add("title", ar[i]);
        }
    }
 
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