So fügen Sie eine Standard-option "Auswählen", um diese ASP.NET DropDownList-Steuerelement?

Ich bin ein neuer ASP.NET Entwickler und ich bin versucht zu lernen, Linq-To-Entities. Ich bin versucht, das binden einer DropDownList mit Linq-Anweisung zum abrufen der Liste der status in der Status-Einheit. Alles ist in Ordnung. Aber ich versuche jetzt hinzufügen "Wählen Sie" option, um die DropDownList, aber Es funktioniert nicht bei mir.
Könnten Sie mir bitte sagen, wie man dieses Problem beheben?

ASP.NET Code:

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
                OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

Code-Behind:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DropDownList1.Items.Add(new ListItem("Select", "0", true));
            bindStatusDropDownList();
        }
    }

private void bindStatusDropDownList()
    {
        Status status = new Status();
        DropDownList1.DataSource = status.getData();
        DropDownList1.DataValueField = "ID";
        DropDownList1.DataTextField = "Description";
        DropDownList1.DataBind();
    }

UPDATE:

Ich habe auch versucht zu tun, in der markup-set der DropDownList, aber es hat nicht funktioniert, auch mit mir

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
                OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                    <asp:ListItem Selected="True" Value="0" Text="Select"></asp:ListItem>
            </asp:DropDownList>
InformationsquelleAutor user3107976 | 2013-12-20
Schreibe einen Kommentar