Click here to Skip to main content
15,790,267 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi all,

My Requirement is, at page load an user can see "---Select color--" option.after click on dropdown list,user can see only "Red" "Green" and "Blue" options.so how to invisible the "---Select color--"option. but my below code still displaying "--select color---","red","blue" & "Green" .plz help me.

Thanks & regards
Papu
.aspx

XML
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
    onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>---Select color--</asp:ListItem>
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
</asp:DropDownList>


.aspx.cs

C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (DropDownList1.SelectedIndex != 0)
    {
       DropDownList1.Items.Remove("---Select color--");
    }
}
Posted
Updated 10-Mar-13 3:08am
v2

1 solution

It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.



For now, you have to do:
1. Raise an event onchange
2. If you find the selected item other than value=0, hide/remove the first item

You can do it on client side or server side as per you need.
 
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