Aspx dropdownlist not displaying top value

Viewed 3573

I have an aspx page (C# code page). I have some hard coded dropdownlists and for some reason they are not displaying the top list item (value). I added an extra top list item (value) and now the correct values display for the values already in it, but that extra one does not display.

The only functionality I do with my dropdownlists in my C# code is to hide or show them. And then do validation or not based on the selected value.

My aspx code:

<asp:DropDownList ID="ddlAction" runat="server" Visible="True" 
    AppendDataBoundItems="true" Height="25px" Width="149px">
    <asp:ListItem Value="Select">Please Select</asp:ListItem>
    <asp:ListItem>Yes</asp:ListItem>
    <asp:ListItem>No</asp:ListItem>
</asp:DropDownList>

C# Code:

ddlAction.Visible = false;
ddlAction.Visible = true;

I use dropdownlist's regularly and have never had this problem before. Does anyone have any ideas what the issue could be?

UPDATE TO THIS ISSUE:

I added my items in my C# code as per Rahul. Did a quick test and it worked. Now this morning, I am once again getting blanks for the first item ("Please Select").

Aspx code:

<asp:DropDownList ID="ddlAction" runat="server" 
 AppendDataBoundItems="True" Height="27px" Width="159px">
 </asp:DropDownList>

C# code:

ddlAction.Visible = true;
ddlAction.AppendDataBoundItems = true;
ddlAction.Items.Insert(0, new ListItem("Please Select","Select"));
ddlAction.Items.Insert(1, new ListItem("Yes", "Yes"));
ddlAction.Items.Insert(2, new ListItem("No", "No"));
ddlAction.DataBind();

Rendered source code:

  &nbsp;<select name="ctl00$ContentPlaceHolder1$ddlAction" id="ContentPlaceHolder1_ddlAction" style="height:27px;width:159px;">
<option selected="selected" value="Select"></option>
<option value="Yes">Yes</option>
<option value="No">No</option>
4 Answers
Related