Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add placeholder in dropdown list c#

Hi I have dropdown list code I want to add placeholder there how I can add?

<asp:DropDownList id="ddlyear" runat="server" >
                     <asp:ListItem >Experience</asp:ListItem>
                     <asp:ListItem>Fresher</asp:ListItem>
                     <asp:ListItem>1</asp:ListItem>
                     <asp:ListItem>2</asp:ListItem>
                     <asp:ListItem>3</asp:ListItem>
</asp:DropDownList>

I want to show like this enter image description here

like image 873
amit Avatar asked Oct 20 '25 11:10

amit


1 Answers

You can just do this:

    <asp:DropDownList id="ddlyear" runat="server" >
                     <asp:ListItem selected hidden>Experience</asp:ListItem>
                     <asp:ListItem>Fresher</asp:ListItem>
                     <asp:ListItem>1</asp:ListItem>
                     <asp:ListItem>2</asp:ListItem>
                     <asp:ListItem>3</asp:ListItem>
    </asp:DropDownList>

The selected makes it the default, while hidden prevents it to be visible on the expanded list.

It's the simplest way possible.

like image 94
II ARROWS Avatar answered Oct 22 '25 23:10

II ARROWS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!