Aspx dropdown does not display top value

I have an aspx page (C # code page). I have some hardcoded dropdownlists and for some reason they do not display the top of the list (value). I added an additional top list item (value), and now the correct values ​​are displayed for existing values, but this additional is not displayed.

The only function that I perform with my dropdownlists in my C # code is to hide or show them. And then check whether 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 regularly and have never had this problem before. Does anyone have any ideas what might be the problem?

UPDATE IN THIS ISSUE:

# Rahul. , . ( ", " ).

Aspx:

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

#:

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();

:

  &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
4

AppendDataBoundItems = true DropSownList .aspx.

,

ddlAction.Items.Insert(0, new ListItem(String.Empty, String.Empty));
+1

AppendDataBound = true aspx.

<asp:DropDownList ID="ddlAction" AppendDataBound = true runat="server" Visible="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>

1

 <asp:ListItem Value="-2" Text="Please Select"></asp:ListItem>
 <asp:ListItem Value="0" Text="Yes"></asp:ListItem>
 <asp:ListItem Value="-1" Text="No"></asp:ListItem>
+1

DropDownList ListItems , ListItem :

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

ASP.NET .

+1
source

I think that you do not need to use, but the method DataBind()does not install AppendDataBoundItems, because you have already inserted it ListItemsand you are not loading parameters from the database!

I think you need to indicate what ListItemIndexis selected by setting the value to the property DropDownList.SelectedIndex.

EDIT

Alternatively, try reading the MSDN documentation on AppendDataBoundItems and enter the link here .

+1
source

All Articles